pyqt timer的应用
来源:互联网 发布:淘宝视频提取真实网址 编辑:程序博客网 时间:2024/05/29 07:21
主要内容
- 主要了解PyQt程序的整体框架;
- 涉及模块:QApplication, QLabel , QTimer
实例讲解
首先先看一个简单的PyQt程序:
1
2
3
4
5
6
7
8
9
10
import
sys
from
PyQt4.QtGui
import
*
from
PyQt4.QtCore
import
*
app
=
QApplication(sys.argv)
label
=
QLabel(
"<font color=red size=128><b>Hello PyQT!</b></font>"
)
label.setWindowFlags(Qt.SplashScreen)
label.show()
QTimer.singleShot(
10000
, app.quit)
# 设置10s后自动退出
app.exec_()
先看导入内容,PyQt中与界面有关的模块一般在QtGui中,而QtCore中包含了很多基本组件。
应用程序整体框架为:
app
=
QApplication(sys.argv)
#...
app.exec_()
中间省略的部分即为自己实现的界面部分,上面的小例子中,将会出现一个小窗口,显示“Hello PyQT!”,接下来一行一行分析。
第6行,我们声明了一个QLabel ,它支持类似于html的语法;
第7行,我们将窗口类型设置为闪屏,这种窗口没有边框,一般用于软件启动画面;若将这句话注释掉,会得到一个正常窗口;
第8行,我们把它的属性设置为可见;
第9行中,我们用QTimer设置定时,10s后退出程序。
简要总结:
- PyQt 程序整体框架, QApplication
- QLabel 标签组件:显示内容
- QTimer定时组件:完成时间调度任务
扩展知识:
QLabel是一种经常使用的的组件,下面的程序提供了更多的关于QLabel用法
主要涉及模块:QFont, QPixMap, QFontMetric, QPainter, QTextDocument,
QLabel 方法:
label.setPixmap(pixmap)
label.setMask(pixmap.createMaskFromColor(Qt.red))
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import
sys
from
PyQt4.QtGui
import
*
from
PyQt4.QtCore
import
*
msg
=
"Hello PyQt!"
app
=
QApplication(sys.argv)
font
=
QFont(
"Times New Rome"
,
36
, QFont.Bold)
fm
=
QFontMetrics(font)
pixmap
=
QPixmap(fm.width(msg)
+
5
, fm.height()
+
5
)
pixmap.fill(Qt.white)
painter
=
QPainter(pixmap)
document
=
QTextDocument()
document.setDefaultFont(font)
document.setHtml(
"<font color=red>%s</font>"
%
msg)
document.drawContents(painter)
label
=
QLabel()
label.setPixmap(pixmap)
label.setMask(pixmap.createMaskFromColor(Qt.red))
#label.setWindowFlags(Qt.SplashScreen|Qt.FramelessWindowHint)
label.show()
QTimer.singleShot(
10000
, app.quit)
# 1 minute
app.exec_()
from PyQt4 import QtCore, QtGui def xxx():def __init__(self): self.timer=QtCore.QTimer() QtCore.QObject.connect(self.timer,QtCore.SIGNAL("timeout()"), self.OnTimer) self.timer.start( 1000 )def OnTimer(self): print 'Get Timer'
0 0
- pyqt timer的应用
- PyQt自定义信号的应用
- Timer的应用
- PyQt基本对话框--表格的应用
- Flex Timer定时器的应用
- JDK Timer定时器的应用
- webkit中timer的应用
- 一个有趣的Timer应用
- Timer控件的简单应用
- 对Timer类的应用
- java定时器Timer的应用
- Timer的应用(java)
- 【转】python--pyqt窗体背景透明的两种应用
- 转摘:一个Timer的简单应用
- Flex Timer定时器的应用(转)
- [转] Linux应用层的定时器Timer
- Linux应用层的定时器Timer
- android中Timer和TimerTask的应用
- 为了让大家更理解vdceye
- JVM调优
- 啊哈C——学习3.7练习
- 社会网络中的心理学-----社交焦虑症
- 检测碰撞
- pyqt timer的应用
- Swift之SDWebImage第三方框架
- java3
- LeetCode-Remove Nth Node From End of List
- Oracle Rac root.sh报错 Failed to create keys in the OLR, rc = 127 libcap.so.1
- java3
- Foundation框架(一)
- HttpClient之https微信获取视屏media_id
- singleton的实现