Home Backend Development Python Tutorial Checkboxes with labels that you must learn every day in PyQt5

Checkboxes with labels that you must learn every day in PyQt5

Apr 19, 2018 pm 01:43 PM
pyqt5 Label

This article mainly introduces in detail the relevant information about check boxes that must be learned every day in PyQt5. It has certain reference value. Interested friends can refer to it

QCheckBox has two types Controls for states: on and off. It's a checkbox with a label. Checkboxes are often used to represent features that an application can enable or disable.


#!/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_())
Copy after login


In our example, we will create a checkbox to toggle the window title.


cb = QCheckBox('显示标题', self)
Copy after login


Use QCheckBox to create a check box


cb.toggle()
Copy after login


The title of the control has been set when creating the check box. By default, the checkbox is unchecked. toggle is to set the checkbox to be selected by default.


cb.stateChanged.connect(self.changeTitle)
Copy after login


The checkbox's state changes stateChanged signal is connected to the changeTitle method (slot).


def changeTitle(self, state):

    if state == Qt.Checked:
      self.setWindowTitle('复选框')
    else:
      self.setWindowTitle('')
Copy after login


The state of the check box control changes to the parameter state passed to the changeTitle method. Sets the window's title if the checkbox control is selected. Otherwise, we set the title bar to an empty string. (Python will define the title as Python when the title is empty)

After the program is executed

Checkboxes with labels that you must learn every day in PyQt5Checkboxes with labels that you must learn every day in PyQt5

Related recommendations:

PyQt5 must learn every day to create a window centering effect

PyQt5 must learn every day to close the window

PyQt5 must learn every day to pop up a message box



The above is the detailed content of Checkboxes with labels that you must learn every day in PyQt5. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to install pyqt5 How to install pyqt5 Nov 30, 2023 pm 02:05 PM

pyqt5 installation steps: 1. Make sure that Python and pip are installed on the computer; 2. Enter the "pip install PyQt5" command in the terminal or command prompt to install PyQt5; 3. After the installation is complete, you can import the PyQt5 module in the Python script and Get started; 4. You can install some specific functions or components by entering the "pip install PyQt5.QtGui" command; 5. If you encounter any problems, you can try to upgrade pip and setuptools.

How to search for text across all tabs in Chrome and Edge How to search for text across all tabs in Chrome and Edge Feb 19, 2024 am 11:30 AM

This tutorial shows you how to find specific text or phrases on all open tabs in Chrome or Edge on Windows. Is there a way to do a text search on all open tabs in Chrome? Yes, you can use a free external web extension in Chrome to perform text searches on all open tabs without having to switch tabs manually. Some extensions like TabSearch and Ctrl-FPlus can help you achieve this easily. How to search text across all tabs in Google Chrome? Ctrl-FPlus is a free extension that makes it easy for users to search for a specific word, phrase or text across all tabs of their browser window. This expansion

Super complete! Python graphical interface framework PyQt5 usage guide! Super complete! Python graphical interface framework PyQt5 usage guide! Apr 13, 2023 am 08:43 AM

Common GUI framework PyQt5: Qt is a cross-platform C++ graphical user interface library. QT was once owned by Nokia and later sold to Digia Oyj, a Finnish software company. PyQt5 is a Python interface based on Digia's Qt5 and consists of a set of Python modules. PyQt5 itself has more than 620 classes and 6000 functions and methods. Can run on multiple platforms, including: Unix, Windows, and Mac OS. Pyside6: Pyside is the Python package officially provided by QT Company. The previous version was Pyside2, which corresponds to QT5. The naming rules of the latest version have been adjusted and changed to Pysid.

What is the clock behind the TikTok label? How to tag Douyin account? What is the clock behind the TikTok label? How to tag Douyin account? Mar 24, 2024 pm 03:46 PM

When browsing Douyin works, we often see a clock icon behind the tag. So, what exactly is this clock? This article will focus on the discussion of "What is the clock behind the Douyin label", hoping to provide some useful reference for your use of Douyin. 1. What is the clock behind the Douyin label? Douyin will launch some hot topic challenges. When users participate, they will see a clock icon after the tag, which means that the work is participating in the topic challenge and displays the remaining time of the challenge. For some time-sensitive content, such as holidays, special events, etc., Douyin will attach a clock icon after the label to remind users of the validity period of the content. 3. Popular tags: When a tag becomes popular, Douyin will add a clock icon after the tag to indicate that the tag is

How to add tags on Douyin to attract traffic? Which tags on the platform are easiest to attract traffic to? How to add tags on Douyin to attract traffic? Which tags on the platform are easiest to attract traffic to? Mar 22, 2024 am 10:28 AM

As a popular short video social platform, Douyin has a huge user base. For Douyin creators, using tags to attract traffic is an effective way to increase the exposure of content and attract attention. So, how does Douyin use tags to attract traffic? This article will answer this question in detail for you and introduce related techniques. 1. How to add tags on Douyin to attract traffic? When posting a video, make sure to choose tags that are relevant to the content. These tags should cover the topic and keywords of your video to make it easier for users to find your video through tags. Leveraging popular hashtags is an effective way to increase your video’s exposure. Research current popular tags and trends and incorporate them into your video descriptions and tags. These popular tags usually have higher visibility and can attract the attention of more viewers. 3. Label

A closer look at the video element in HTML A closer look at the video element in HTML Feb 24, 2024 pm 08:18 PM

Detailed explanation of the video tag in HTML The video tag in HTML5 is a tag used to play videos on web pages. It can render videos using different formats, such as MP4, WebM, Ogg, and more. In this article, we will introduce the use of video tag in detail and provide specific code examples. Basic Structure The following is the basic structure of the video tag:

What is the difference between html5 tag head and header? What is the difference between html5 tag head and header? Jan 17, 2022 am 11:10 AM

Differences: 1. The head tag is used to define the head of the document, which is a container for all head elements, and the header tag is used to define the header (introduction information) of the document; 2. All browsers support the head tag, and older versions of browsers None of the browsers support the header tag, and browsers such as IE9+ and above are required to support the header tag.

How to delete external contact tags on DingTalk app How to delete external contact tags on DingTalk app Feb 24, 2024 am 08:20 AM

How to delete external contact tags on DingTalk app? DingTalk has a function to delete external contact tags, but most friends don’t know how to delete external contact tags on DingTalk. Next is the DingTalk guide that the editor brings to users. Graphical tutorial on how to delete external contact tags in the Ding app. Interested users can come and take a look! How to delete external contact tags in DingTalk app 1. First open DingTalk APP and click the [Management] function as shown below on the main page; 2. Then enter the enterprise management interface and find [External Contacts]; 3. Then on the external contact setting function page, select the [Label Management] service; 4. Then on the main contact label page, select the type of label group you want to delete; 5. Finally, click on the red label group

See all articles