QtGui.QCheckBox
A QtGui.QCheckBox is a widget that has two states: on and off. It is a box with a label. Check boxes are typically used to represent features in an application that can be enabled or disabled.
#!/usr/bin/python
# -*- coding: utf-8 -*- """
ZetCode PyQt4 tutorial In this example, a QtGui.QCheckBox widget
is used to toggle the title of a window. author: Jan Bodnar
website: zetcode.com
last edited: September 2011
""" import sys
from PyQt4 import QtGui, QtCore class Example(QtGui.QWidget): def __init__(self):
super(Example, self).__init__() self.initUI() def initUI(self): cb = QtGui.QCheckBox('Show title', self)
cb.move(20, 20)
cb.toggle()
cb.stateChanged.connect(self.changeTitle) self.setGeometry(300, 300, 250, 150)
self.setWindowTitle('QtGui.QCheckBox')
self.show() def changeTitle(self, state): if state == QtCore.Qt.Checked:
self.setWindowTitle('QtGui.QCheckBox')
else:
self.setWindowTitle('') def main(): app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_()) if __name__ == '__main__':
main()
In our example, we will create a checkbox that will toggle the window title.
cb = QtGui.QCheckBox('Show title', self)
This is a QtGui.QCheckBox constructor.
cb.toggle()
We have set the window title, so we must also check the checkbox. By default, the window title is not set and the checkbox is unchecked.
cb.stateChanged.connect(self.changeTitle)
We connect the user defined changeTitle() method to the stateChanged signal. The changeTitle()method will toggle the window title.
def changeTitle(self, state):
if state == QtCore.Qt.Checked:
self.setWindowTitle('QtGui.QCheckBox')
else:
self.setWindowTitle('')
The state of the widget is given to the changeTitle() method in the state variable. If the widget is checked, we set a title of the window. Otherwise, we set an empty string to the titlebar.
Figure: QtGui.QCheckBox
QtGui.QCheckBox的更多相关文章
- PyQt4单选框QCheckBox
PyQt4中的部件 部件是构建应用程序的基础元素.PyQt4工具包拥有大量的种类繁多的部件.比如:按钮,单选框,滑块,列表框等任何程序员在完成其工作时需要的部件. QCheckBox单选框 单选框具有 ...
- Pyqt 获取打包二进制文件中的资源
记得有一次打开一个单独exe程序,点击btn中的一个帮助说明按钮,在同级目录下就多出一个help.chm 文件并自动打开. 那这个exe肯定是把help.chm 打包到exe中,当我触发“帮助”按钮的 ...
- Pyqt 屏幕截图工具
从Pyqt的examples中看到一段截图代码, (路径:examplas\desktop\screenshot.py) 所以想自己UI下界面,手动练习下 通过UI生成的: Screenshot.py ...
- Pyqt Smtplib实现Qthread多线程发送邮件
一. smtplib 的介绍 smtplib.SMTP([host[, port[, local_hostname[, timeout]]]]) SMTP类构造函数,表示与SMTP服务器之间的连接 ...
- Pyqt QSystemTrayIcon 实现托盘效果
pyqt的托盘效果很好实现,在Pyqt的demo中有个例子 路径:PyQt4\examples\desktop\systray.py 今天我就仿这个Tray效果做效果 一. 创建UI trayicon ...
- pyqt小例子 音乐盒
源代码1: # -*- coding: utf-8 -*- import sys,time,os import ctypes from PyQt4 import QtCore, QtGui,Qt fr ...
- PYQT4 : QSystemTrayIcon练习
照着demo自己做了一遍,练练手 import sys from PyQt4 import QtGui from PyQt4 import QtCore class SysTray(QtGui.QDi ...
- Python&MySQL&PyQt
环境: Python2.7+MySQL5.6+PyQt4 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/40 ...
- PyQt4 的部件 -- CheckBox 单选框
单选框具有两种状态:被选中或未被选中. 当用户选择或者取消选择时,单选框就会发射一个stateChanged()信号 # QCheckBox 单选框 # 本例创建一个用来改变窗口标题的单选框 impo ...
随机推荐
- poj 3744 概率dp+矩阵快速幂
题意:在一条布满地雷的路上,你现在的起点在1处.在N个点处布有地雷,1<=N<=10.地雷点的坐标范围:[1,100000000]. 每次前进p的概率前进一步,1-p的概率前进1-p步.问 ...
- VK Cup 2016 - Qualification Round 2 B. Making Genome in Berland 水题
B. Making Genome in Berland 题目连接: http://www.codeforces.com/contest/638/problem/B Description Berlan ...
- CROC 2016 - Elimination Round (Rated Unofficial Edition) C. Enduring Exodus 二分
C. Enduring Exodus 题目连接: http://www.codeforces.com/contest/655/problem/C Description In an attempt t ...
- 发展中的生命力——Leo鉴书69
接触<寻路中国>是在2011年11月24号的正略读书会上.当期主讲嘉宾是万圣书园创始人刘苏里,也是著名的大书评人.读书会有个传统就是每期推荐一本书.当期推荐就是<寻路中国>.事 ...
- PEM DAC note
开发指南V1.0库函数版本,PWM DAC实验 350页 STM32 的定时器最快的计数频率是72Mhz,8 为分辨率的时候,PWM 频率为72M/256=281.25Khz.如果是1阶RC滤波,则要 ...
- php中的var_dump()方法的详细说明
首先看看实例: <?PHP$a = "alsdflasdf;a";$b = var_dump($a);echo "<br>";//var_du ...
- 阿里云+django实战记录
2013年7月13日10:36:53:接上篇,bae部署django没成功,转战阿里云.. 阿里云服务器最便宜69/月,现在有个活动,新用户送20元现金券,我就花了RMB 49买了一个,操作系统选的是 ...
- js 实现纯前端将数据导出excel
通过将json遍历进行字符串拼接,将字符串输出到csv文件,输出的文件不会再是html类型的文件而是真正的csv文件,代码如下 <html> <head> <p styl ...
- redis+spring配置
pom引入jedis的jar包 <dependency> <groupId>redis.clients</groupId> <artifactId>je ...
- delphi 搭建安卓开发环境
delphi 搭建安卓开发环境 DELPHI安装成功以后,怀着激动的心情,使用IDE向导生成安卓DEMO程序,BUILD,想马上看到编译成功的提示,结果报错,不由得傻眼了.DELPHI怎么这么差? 原 ...