Python Forum
[PyQt] Add command to PushButton
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] Add command to PushButton
#1
I create a GUI usin PyQt5 Designer
and i want to know how to make that the push buttons trigger a py. script?
whats the command for that?
i already convert from .ui to .py and this was the result script

from PyQt5 import QtCore, QtGui, QtWidgets, uic

class GUI_PLC_1(QtWidgets.QMainWindow):
    def __init__(self):
        super(GUI_PLC_1,self).__init__()
        uic.loadUi('GUI_PLC.ui',self)

if __name__ == '__main__':
    import sys
    app = QtWidgets.QApplication(sys.argv)
    window = GUI_PLC_1()
    window.show()
    sys.exit(app.exec_())
Reply
#2
You can access controls in your UI through the value returned by uic.loadUI.
class GUI_PLC_1(QtWidgets.QMainWindow):
    def button_clicked(self):
        print('Click!')

    def __init__(self):
        super(GUI_PLC_1,self).__init__()
        self.ui = uic.loadUi('GUI_PLC.ui',self)
        self.ui.clickything.clicked.connect(self.button_clicked)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyGUI] Pushbutton in ANSA Aishaf 2 2,565 Apr-27-2021, 11:22 AM
Last Post: Aishaf
  [PyQt] pushbutton with image issac_n 1 1,737 Jul-13-2020, 05:04 PM
Last Post: Knight18
  TypeError when using PushButton (PyQt5) lmsavk 1 6,665 Mar-03-2019, 04:21 PM
Last Post: Alfalfa
  pyqt clickable pushbutton problem pythonck 1 7,591 Dec-12-2017, 03:38 PM
Last Post: pythonck
  keeping track of pushbutton click iFunKtion 3 4,211 Mar-13-2017, 12:18 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020