因此,当 Beagleboard 上的 GPIO 引脚设置为高电平时,我试图弹出一个警告窗口。给定我的 Adafruit,我的代码可以使用 BBIO 库在控制台中轻松运行。但是,当使用应用于 pyside 库的相同逻辑时,程序会忽略“if”子句并自动运行弹出窗口。即使是简单的弹出窗口,程序也会忽略 if 语句。任何帮助或想法表示赞赏。
#console code
import Adafruit_BBIO.GPIO as GPIO
from time import sleep #handy sleep command
GPIO.setup("P8_16", GPIO.IN)
while True:
if GPIO.input("P8_16"):
print ("Battery Low on the Down low!!")
sleep (1.25)
else:
pass
#popup code
import sys
from PySide.QtCore import *
from PySide.QtGui import *
import time
import Adafruit_BBIO.GPIO as GPIO
from time import sleep #handy sleep command
GPIO.setup("P8_16", GPIO.IN) #set GPIO port
while True:
if GPIO.input("P8_16"):
#sleep(1)
def window():
app = QApplication(sys.argv)
w = QWidget()
b = QPushButton(w)
b.setText("Battery is Low!")
b.move(100,100)
b.clicked.connect(showdialog)
w.setWindowTitle("Battery Alert")
w.show()
sys.exit(app.exec_())
def showdialog():
msg = QMessageBox()
msg.setIcon(QMessageBox.Warning)
msg.setText("Please recharge the Tracker battery")
msg.setInformativeText("To exit simply close the windows")
msg.setWindowTitle("Battery Low")
msg.setDetailedText("Please recharge the Tracker unit")
msg.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel)
msg.buttonClicked.connect(msgbtn)
retval = msg.exec_()
print "value of pressed message box button:", retval
def msgbtn(i):
print "Button pressed is:",i.text()
if __name__ == '__main__':
window()
else:
pass
sleep(1)