#!/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. libgomp-4.8.5-28.el7_5.1.x86_64 is a duplicate with libgomp-4.8.5-4.el7.x86_64

    列出重复的包 # package-cleanup --dupes 删除重复的包 # package-cleanup --cleandupes

  2. 2.7 The Object Model -- Bindings, Observers, Computed Properties:What do I use when?

    有时候新用户在使用计算属性.绑定和监视者时感到困惑.下面是一些指导方针: 1. 使用computed properties来合成其他属性,以构建新的属性.computed properties不应该包 ...

  3. Session应用之验证码

    package com.aeolia.view; import java.awt.Color; import java.awt.Font; import java.awt.image.Buffered ...

  4. php-fpm开启报错-ERROR: An another FPM instance seems to already listen on /tmp/php-cgi.sock

    在升级了php7.2.0版本之后,重新启动php-fpm过程中遇到一个报错. An another FPM instance seems to already listen on /tmp/php-c ...

  5. mailx配置安装

    mailxwget http://ftp.debian.org/debian/pool/main/h/heirloom-mailx/heirloom-mailx_12.5.orig.tar.gztar ...

  6. nodejs 8 利用原生 util.promisify() 实现 promise.delay()

    Nodejs 8 在 util 包里新增了 promisify() .这个方法基本和 bluebird 的 promisify() 作用一样,即把最后一个参数是 callback 函数的函数变成返回 ...

  7. [BZOJ3237]连通图

    Description Input Output Sample Input 4 5 1 2 2 3 3 4 4 1 2 4 3 1 5 2 2 3 2 1 2 Sample Output Connec ...

  8. SpringBoot基础的使用

    springboot的基础使用 和 内部原理 高级使用整合 进行web开发 springboot 看下spring的所有项目:https://spring.io/projects 等等 就不一一介绍了 ...

  9. Maven编译代码的时候跳过单元测试

    Maven编译代码的时候跳过单元测试 <properties> <maven.test.skip>true</maven.test.skip> </prope ...

  10. luogu P1017 进制转换

    感觉这个题 是真的恶心 本来单纯就递归写,发现好难 后来用数组记录 然后考虑 指数为 奇和偶数 分别 <0 和 > 进制的情况 其实 用进制数为3 大概讨论四种情况就可以了 由于最近就是在 ...