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_()
所以我试图创建一个按钮来运行上面的程序。我以前用过一个物理按钮,但现在我想做一个数字显示。我已经在QT5 designer上创建了按钮,但似乎无法集成它
TL;您可以将现有代码集成到UI,而不是反之亦然。如果您只需要一个按钮,那么直接用python编写ui就容易多了,但是由于您已经有了
ui
文件,这个答案就是这样的使用PyQt5的
pyside2-uic
或pyuic
转换.ui
文件以将其转换为python代码例如,对于带有PySide2的windows cmd:
将
main.ui
更改为相应的.ui
文件位置要使用生成的python脚本,最好导入并创建它的子类,以备将来可能进行的更改
下面的示例假设您只有一个名为
pushButton
的按钮,并用作打开或关闭函数的切换按钮只需将逻辑复制粘贴到
function_to_be_run
,将pushButton
更改为您的QPushButton的名称,并将time.sleep()
调用更改为event.wait()
就足够了,但我建议先研究代码请注意:
Qrunnable
中的任何一个都可以在内部处理可调用函数的并发运行,但看起来您的任务并不复杂,直接使用threading
模块会更直接李>thread
和event
的引用存储在本地之外李>如果你只有两个按钮——开始、停止,那就容易多了
相关问题 更多 >
编程相关推荐