PyQt编程第7章 使用Qt Designer
用户界面保存在.ui文件中,包含一个窗口部件和布局的详细情况。Qt Designer能够关联标签和它的伙伴,
设置tab顺序(这个也可以用QWidget.setTabOrder()完成)。Qt Designer也能够关联信号和槽,
但是只能是内置的信号和槽。
用户界面保存在.ui文件中,包含一个窗口部件和布局的详细情况。Qt Designer能够关联标签和它的伙伴,
设置tab顺序(这个也可以用QWidget.setTabOrder()完成)。Qt Designer也能够关联信号和槽,
但是只能是内置的信号和槽。
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.
sum = 3 * (1 + 999 / 3) * (999 / 3) / 2 + \
5 * (1 + 999 / 5) * (999 / 5) / 2 - \
15 * (1 + 999 / 15) * (999 / 15) / 2
print sum如果我们列出所有小于10且为3或5的倍数的自然数,我们得到3,5,6和9。这些数的和是23。找出所有低于1000且为3或5倍数的和。
import os
import platform
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import helpform
import newimagedlg
import qrc_resources
__version__ = "1.0.0"import的顺序:先Python标准模块,然后第三方模块(比如PyQt),最后自己定义的模块。
一个程序通常有一个版本字符串,按照惯例称为__version__。
对话框以“智力”分类为:哑巴,标准和聪明,取决于对话框知道程序数据的多少。 对话框以“模式”分类为:模式对话框和无模式对话框。
应用模式对话框一旦被调用,用户只能与其交互,不能使用程序其它部分。 窗口模式对话框和应用模式对话框类似,只是它仅仅阻止与其父窗口交互。 无模式对话框允许用户与程序其它部分交互。
import sys
import time
from PyQt4.QtCore import *
from PyQt4.QtGui import *
app = QApplication(sys.argv)
try:
due = QTime.currentTime()
message = "Alert!"
if len(sys.argv) < 2:
raise ValueError
hours, mins = sys.argv[1].split(":")
due = QTime(int(hours), int(mins))
if not due.isValid():
raise ValueError
if len(sys.argv) > 2:
message = " ".join(sys.argv[2:])
except ValueError:
message = "Usage: alert.pyw HH:MM [optional message]" # 24hr clock
while QTime.currentTime() < due:
time.sleep(20) # 20 seconds
label = QLabel("<font color=red size=72><b>" + message + "</b></font>")
label.setWindowFlags(Qt.SplashScreen)
label.show()
QTimer.singleShot(60000, app.quit) # 1 minute
app.exec_()每一个PyQt图形程序必须有一个QApplication对象,因为它能识别一些命令行的参数,接受sys.argv作为
参数。