This article mainly for you in detail the PYQT5 every day must learn the check box of relevant information, with a certain reference value, interested in small partners can refer to
Qcheckbox is a control with two states: on and off. It is a check box with a label. Check boxes are typically used to indicate features that an application can enable or disable.
#!/usr/bin/python3#-*-coding:utf-8-*-"" "PYQT5 tutorial in this example, a Qcheckbox control is used to toggle the caption of the window. Author: My World You've been to the blog: Http://blog.csdn.net/weiaitaowang Last edited: August 3, 2016 "" "Import sysfrom pyqt5.qtwidgets Import Qapplication, Qwidget, qcheckboxfrom pyqt5.qtcore import qtclass Example (qwidget): def __init__ (self): super ( ). __init__ () Self.initui () def initui (self): cb = Qcheckbox (' Show title ', self) cb.move (+) Cb.toggle () cb.stateChanged.connect (self.changetitle) self.setgeometry (+, +) Self.setwindowtitle (' check box ') self.show () def changetitle (self, State): if state = = qt.checked: Self.setwindowtitle (' check box ') else: self.setwindowtitle (") if __name__ = = ' __main__ ': app = Qapplication (SYS.ARGV) ex = Example () sys.exit (App.exec_ ())
In our example, we will create a check box to toggle the window caption.
CB = Qcheckbox (' Show title ', self)
Create a check box with Qcheckbox
Cb.toggle ()
The caption of the control has been set when the check box was created. By default, the check box is not selected. Toggle is the Set check box is selected by default.
Cb.stateChanged.connect (Self.changetitle)
The State of the check box changes the statechanged signal to the Changetitle method (slot).
def changetitle (self, State): if state = = qt.checked: self.setwindowtitle (' check box ') else: Self.setwindowtitle (")
The State of the check box control is passed to the parameter of the Changetitle method. If the check box control is selected, the caption of the window is set. Otherwise, we set the title bar of an empty string. (Python will define the title as Python when the title is empty)
After the program executes