#!/usr/bin/python
# -*- coding: utf-8 -*- """
ZetCode PyQt4 tutorial In this example, we create a simple
window in PyQt4. author: Jan Bodnar
website: zetcode.com
last edited: October 2011
"""
# Here we provide the necessary imports. The basic GUI widgets are located in the QtGui module.
import sys
from PyQt4 import QtGui def main(): # Every PyQt4 application must create an application object. The application object is located in the QtGui module. The sys.argv parameter is a list of arguments from the command line. Python scripts can be run from the shell. It is a way how we can control the startup of our scripts.
app = QtGui.QApplication(sys.argv) # The QtGui.QWidget widget is the base class of all user interface objects in PyQt4. We provide the default constructor for QtGui.QWidget. The default constructor has no parent. A widget with no parent is called a window.
w = QtGui.QWidget()
# The resize() method resizes the widget. It is 250px wide and 150px high.
w.resize(250, 150)
# The move() method moves the widget to a position on the screen at x=300 and y=300 coordinates.
w.move(300, 300)
# Here we set the title for our window. The title is shown in the titlebar.
w.setWindowTitle('Simple')
# The show() method displays the widget on the screen. A widget is first created in memory and later shown on the screen.
w.show() # Finally, we enter the mainloop of the application. The event handling starts from this point. The mainloop receives events from the window system and dispatches them to the application widgets. The mainloop ends if we call the exit() method or the main widget is destroyed. The sys.exit() method ensures a clean exit. The environment will be informed how the application ended.
# The exec_() method has an underscore. It is because the exec is a Python keyword. And thus, exec_() was used instead.
sys.exit(app.exec_()) # When the Python interpreter reads a source file, it executes all of the code found in it. Before executing the code, it will define a few special variables. For example, if the python interpreter is running that module (the source file) as the main program, it sets the special __name__ variable to have a value "__main__". If this file is being imported from another module, __name__ will be set to the module's name.
if __name__ == '__main__':
main()

ZetCode PyQt4 tutorial First programs的更多相关文章

  1. ZetCode PyQt4 tutorial Drag and Drop

    #!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial This is a simple ...

  2. ZetCode PyQt4 tutorial widgets II

    #!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial In this example, ...

  3. ZetCode PyQt4 tutorial widgets I

    #!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial In this example, ...

  4. ZetCode PyQt4 tutorial Dialogs

    #!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial In this example, ...

  5. ZetCode PyQt4 tutorial signals and slots

    #!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial In this example, ...

  6. ZetCode PyQt4 tutorial layout management

    !/usr/bin/python -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial This example shows ...

  7. ZetCode PyQt4 tutorial work with menus, toolbars, a statusbar, and a main application window

    !/usr/bin/python -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial This program create ...

  8. ZetCode PyQt4 tutorial custom widget

    #!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial In this example, ...

  9. ZetCode PyQt4 tutorial basic painting

    #!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial In this example, ...

随机推荐

  1. 2017-2018 ACM-ICPC, Asia Daejeon Regional Contest Solution

    A:Broadcast Stations 留坑. B:Connect3 题意:四个栈,每次放棋子只能放某个栈的栈顶,栈满不能放,现在给出(1, x) 表示黑子放在第x个栈的第一个位置,白子放在第b个栈 ...

  2. mysql数据库设置不区分大小写,启动方法

    用root帐号登录后,在/etc/my.cnf中的[mysqld]后添加添加lower_case_table_names=1,重启MYSQL服务,这时已设置成功:不区分表名的大小写: lower_ca ...

  3. 使用JavaScript下载csv文件

    前端可以使用JavaScript在客户端下载包含页面数据的文件,这里以下载CSV格式文件为例,代码如下: function downloadData(data, filename, type) { v ...

  4. MVC中定时发布二维码邮件

    发布邮件 查看第一个方法就可以了,第二个跟这个无关 using System; using System.Collections.Generic; using System.Linq; using S ...

  5. UVa 10791 最小公倍数的最小和(唯一分解定理)

    https://vjudge.net/problem/UVA-10791 题意: 输入整数n,求至少两个正整数,使得它们的最小公倍数为n,且这些整数的和最小. 思路: 首先对n进行质因数分解,举个例子 ...

  6. Uva 12304 - 2D Geometry 110 in 1!

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  7. Java中的组合与聚合

    组合和聚合是有很大区别的,这个区别不是在形式上,而是在本质上:比如A类中包含B类的一个引用b,当A类的一个对象消亡时,b这个引用所指向的对象也同时消亡(没有任何一个引用指向它,成了垃圾对象),这种情况 ...

  8. python 返回列表中的偶数

    def is_even_num(l): enum = [] for n in l: == : enum.append(n) return enum print(is_even_num([, , , , ...

  9. c++ 字符串拷贝以及合并

    #include<iostream> #include<string> using namespace std; class stringfun { ]; public: vo ...

  10. PHP 手机号中间4位加密

    /** * 中间加密 字符串截取法 */ public static function encryptTel($tel) { $new_tel = substr($tel, 0, 3).'****'. ...