Python PyQt5 CHECKBOXES are easy! ✅

แชร์
ฝัง
  • เผยแพร่เมื่อ 17 ต.ค. 2024
  • #pythontutorial #python #pythonprogramming
    PyQt5 Checkboxes
    import sys
    from PyQt5.QtWidgets import QApplication, QMainWindow, QCheckBox
    from PyQt5.QtCore import Qt
    class MainWindow(QMainWindow):
    def __init__(self):
    super().__init__()
    self.setGeometry(700, 300, 500, 500)
    self.checkbox = QCheckBox("Do you like food?", self)
    self.initUI()
    def initUI(self):
    self.checkbox.setGeometry(10, 0, 500, 100)
    self.checkbox.setStyleSheet("font-size: 30px;"
    "font-family: Arial;")
    self.checkbox.stateChanged.connect(self.checkbox_changed)
    def checkbox_changed(self, state):
    if state == Qt.Checked:
    print("You like food")
    else:
    print("You DO NOT like food")
    if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = MainWindow()
    window.show()
    sys.exit(app.exec_())

ความคิดเห็น • 5

  • @BroCodez
    @BroCodez  2 หลายเดือนก่อน +1

    # PyQt5 Checkboxes
    import sys
    from PyQt5.QtWidgets import QApplication, QMainWindow, QCheckBox
    from PyQt5.QtCore import Qt
    class MainWindow(QMainWindow):
    def __init__(self):
    super().__init__()
    self.setGeometry(700, 300, 500, 500)
    self.checkbox = QCheckBox("Do you like food?", self)
    self.initUI()
    def initUI(self):
    self.checkbox.setGeometry(10, 0, 500, 100)
    self.checkbox.setStyleSheet("font-size: 50px;"
    "font-family: Arial;")
    self.checkbox.stateChanged.connect(self.checkbox_changed)
    def checkbox_changed(self, state):
    if state == Qt.Checked:
    print("You like food")
    else:
    print("You DO NOT like food")
    if ___name___ == '__main__':
    app = QApplication(sys.argv)
    window = MainWindow()
    window.show()
    sys.exit(app.exec_())

  • @familovegamehub4513
    @familovegamehub4513 2 หลายเดือนก่อน +1

    Teaching people how to code in an easily understandable way. What a legend

  • @ranjithsingh8577
    @ranjithsingh8577 หลายเดือนก่อน

    I like u code bro .❤

  • @RHANIMATIONS
    @RHANIMATIONS 2 หลายเดือนก่อน

    Bro can you make c# advance tutorials coz I m going with c# + thank you so much bro for creating such free and best courses for the other bros
    True bro 🗿

  • @fiftys7ven
    @fiftys7ven 2 หลายเดือนก่อน

    hello :)