2016-09-30 11:31:51 +08:00
|
|
|
|
# Hello World
|
|
|
|
|
|
2016-10-04 13:12:43 +08:00
|
|
|
|
##本章学习Qt的基本功能
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
这个简单的小例子展示的是一个小窗口。但是我们可以在这个小窗口上面做很多事情,改变大小,最大化,最小化等,这需要很多代码才能实现。这在很多应用中很常见,没必要每次都要重写这部分代码,Qt已经提供了这些功能。PyQt5是一个高级的工具集合,相比使用低级的工具,PyQt能省略上百行代码。
|
|
|
|
|
|
|
|
|
|
``` python
|
|
|
|
|
#!/usr/bin/python3
|
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
ZetCode PyQt5 tutorial
|
|
|
|
|
|
|
|
|
|
In this example, we create a simple
|
|
|
|
|
window in PyQt5.
|
|
|
|
|
|
|
|
|
|
author: Jan Bodnar
|
|
|
|
|
website: zetcode.com
|
|
|
|
|
last edited: January 2015
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
from PyQt5.QtWidgets import QApplication, QWidget
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
|
|
|
|
|
app = QApplication(sys.argv)
|
|
|
|
|
|
|
|
|
|
w = QWidget()
|
|
|
|
|
w.resize(250, 150)
|
|
|
|
|
w.move(300, 300)
|
|
|
|
|
w.setWindowTitle('Simple')
|
|
|
|
|
w.show()
|
|
|
|
|
|
|
|
|
|
sys.exit(app.exec_())
|
|
|
|
|
```
|
|
|
|
|
运行上面的代码,能展示出一个小窗口。下面是每行代码的讲解。
|
|
|
|
|
```
|
|
|
|
|
import sys
|
|
|
|
|
from PyQt5.QtWidgets import QApplication, QWidget
|
|
|
|
|
```
|