from pages import*
import time
import sys
#GPIO Pins Setup
buzzer_motor = 12
#input from physical switch
button = 16
GPIO.setmode(GPIO.BCM)
GPIO.setup(button, GPIO.IN, pull_up_down = GPIO.PUD_UP)
#output to motor which is connected to pin 12
GPIO.setup(buzzer_motor, GPIO.OUT)
a = 0
def Mag_Train():
GPIO.output(buzzer_motor, True)
time.sleep(.3)
GPIO.output(buzzer_motor, False)
result = "Success"
print(time.asctime())
time_end = time.asctime()
time.sleep(1)
return [time_end,result]
while(a == 0):
if(GPIO.input(button) == False):
Mag_Train()
# def sayHello():
# print("Push Button Clicked")
# button = True
#
# app = QApplication(sys.argv)
# magazineStart = magazineStart("MAGAZINE START")
# magazineStart.clicked.connect(sayHello)
# magazineStart.show()
# app.exec_()
So i am trying to create a pushbutton that runs the program above. I previously used a physical push button, but now i want to do a digital display. I already created the button on QT5 designer but cant seem to integrate it
TL;DR You integrate existing code to UI, not vise versa. It's way easier writing ui in python directly if you only need one button, but as you already have
uifile, this answer will head that way.Use
pyside2-uicorpyuicfor PyQt5 - I presume - to convert.uifile to convert it into python code.For example in case of windows cmd with PySide2:
Change
main.uito respective.uifile location.To use generated python script, it's better to import and create subclass of it in case for future changes you might do later.
Following example assumes that you only have one button called
pushButton, and work as toggle button that turns on, or off your function.Mere copy-paste your logic to
function_to_be_run, changepushButtonto your QPushButton's name and changingtime.sleep()calls toevent.wait()would work out of box well enough, but I'd recommend studying code first.Do note:
Qrunnablethat handles concurrent run of callable internally, but seems like your task is not complex and usingthreadingmodule directly would be more straightfoward.threadandeventoutside local.Would be way easier if you just have 2 buttons - start, stop.