Python Forum

Full Version: Add command to PushButton
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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_())
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)