Python Forum
[PyQt] Add command to PushButton - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: [PyQt] Add command to PushButton (/thread-25757.html)



Add command to PushButton - skaailet - Apr-11-2020

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_())



RE: Add command to PushButton - deanhystad - Apr-11-2020

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)