PYQT5 every day must learn the label check box

Source: Internet
Author: User
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.