from PyQt5.QtWidgets import QApplication, QMainWindow, QCheckBox class MainWindow(QMainWindow): def __init__(self): super().__init__() # Creating a QCheckBox control self.checkbox = QCheckBox('Show Text', self) self.checkbox.setChecked(True) self.checkbox.move(10, 10) # Hiding the QCheckBox control self.checkbox.hide() if __name__ == '__main__': app = QApplication([]) window = MainWindow() window.show() app.exec()
from PyQt5.QtWidgets import QApplication, QMainWindow, QCheckBox, QPushButton class MainWindow(QMainWindow): def __init__(self): super().__init__() # Creating a QCheckBox control self.checkbox = QCheckBox('Show Text', self) self.checkbox.setChecked(True) self.checkbox.move(10, 10) # Creating a QPushButton to toggle the visibility of the QCheckBox control self.button = QPushButton('Hide/Show', self) self.button.clicked.connect(self.toggle_checkbox) self.button.move(10, 40) def toggle_checkbox(self): if self.checkbox.isHidden(): self.checkbox.show() else: self.checkbox.hide() if __name__ == '__main__': app = QApplication([]) window = MainWindow() window.show() app.exec()In this example, a QCheckBox control and a QPushButton are created. The QPushButton is used to toggle the visibility of the QCheckBox control. The toggle_checkbox function is called when the QPushButton is clicked, and it checks if the QCheckBox control is hidden or not. If it is hidden, it is shown; otherwise, it is hidden.