PyQt5每天必学之带有标签的复选框
作者:我的世界你曾经来过 时间:2021-04-30 05:27:06
QCheckBox 是具有两种状态的控件:开和关。它是一个带有标签的复选框。复选框通常用于表示应用程序可以启用或禁用的功能。
#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
PyQt5 教程
在这个例子中,一个QCheckBox控件用于切换窗口的标题。
作者:我的世界你曾经来过
博客:http://blog.csdn.net/weiaitaowang
最后编辑:2016年8月3日
"""
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QCheckBox
from PyQt5.QtCore import Qt
class Example(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
cb = QCheckBox('显示标题', self)
cb.move(20, 20)
cb.toggle()
cb.stateChanged.connect(self.changeTitle)
self.setGeometry(300, 300, 250, 150)
self.setWindowTitle('复选框')
self.show()
def changeTitle(self, state):
if state == Qt.Checked:
self.setWindowTitle('复选框')
else:
self.setWindowTitle('')
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
在我们的例子中,我们将创建一个复选框进行窗口标题的切换。
cb = QCheckBox('显示标题', self)
用QCheckBox 创建复选框
cb.toggle()
创建复选框时已经设置了控件的标题。默认情况下,复选框是不被选中的。toggle是设置复选框默认为选中。
cb.stateChanged.connect(self.changeTitle)
复选框的状态更改stateChanged信号连接到changeTitle方法(槽)。
def changeTitle(self, state):
if state == Qt.Checked:
self.setWindowTitle('复选框')
else:
self.setWindowTitle('')
复选框控件的状态改变传递给changeTitle方法的参数state。如果复选框控件被选中,设置窗口的标题。否则,我们设置一个空字符串的标题栏。(空标题时Python会将标题定义成Python)
程序执行后
来源:https://blog.csdn.net/weiaitaowang/article/details/52101948
标签:PyQt5,复选框
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
聊天室php&mysql(五)
2023-11-19 20:18:22
HTML4标签的默认样式列表
2007-09-28 22:00:00
数据库应用经验:如何简单安装MySQL数据库
2009-01-04 12:58:00
数据库手边系列:SQL Server数据表信息
2009-05-24 18:26:00
网站tab导航的设计
2008-11-10 12:36:00
![](https://img.aspxhome.com/file/UploadPic/200811/10/tab1-53s.jpg)
asp如何检测HTTP表头信息?
2010-06-28 18:20:00
浅析Python中的getattr(),setattr(),delattr(),hasattr()
2022-11-10 08:26:41
SQL Server 2005 SSIS技巧:动态目的文件名
2008-12-05 15:47:00
如何用python合并多个excel文件
2022-08-23 19:30:24
![](https://img.aspxhome.com/file/2023/2/81822_0s.png)
php设计模式 Singleton(单例模式)
2023-11-20 14:37:50
python跳过第一行快速读取文件内容的实例
2022-05-12 12:58:56
设计规范有谱么?
2008-06-06 12:28:00
Pycharm5个非常有用的方法技巧
2023-12-03 00:19:08
![](https://img.aspxhome.com/file/2023/0/75120_0s.png)
对TensorFlow中的variables_to_restore函数详解
2022-09-11 00:49:19
Flask框架踩坑之ajax跨域请求实现
2023-12-25 01:28:02
![](https://img.aspxhome.com/file/2023/3/80703_0s.png)
OpenCV-Python使用cv2实现傅里叶变换
2023-07-08 05:11:06
![](https://img.aspxhome.com/file/2023/2/76692_0s.png)
Python中psutil模块使用汇总
2022-07-30 10:26:45
![](https://img.aspxhome.com/file/2023/0/64670_0s.jpg)
asp连接各种数据库代码
2008-03-11 11:16:00
![](https://img.aspxhome.com/file/UploadPic/20083/11/2008311115714589s.jpg)
go-cache的基本使用场景示例解析
2023-08-06 00:52:02
Access数据库中“所有记录中均未找到搜索关键字”的解决方法
2011-04-14 10:31:00