1

我想使用buttonBox(来自 Python easyGUI)来触发 Python 中的函数。但我不知道该怎么做。按钮框代码如下:

buttonbox(msg='Robot Moving', title=' ', choices=('MoveFwd', 'MoveBwd', 'TurnR','TurnL'), image=None)

我想通过单击“MoveFwd”按钮来触发机器人向前移动。Python 中的 MoveFwd 已关闭并已编译。请参阅下面的代码。

def MoveFwd():
    ser = serial.Serial(3)
    print ser.name
    print 'Start Moving Fwd...'
    ser.write('SetMotor RWheelDist 200 Speed 100 LWheelDist 200 Speed 100 \n')
moveFwd()

那么我的问题是,如何将这两者联系在一起?

4

1 回答 1

0

EasyGui 就是这样。您可能会花时间更好地利用学习 Tkinter,因为它非常简单,并且会做这些事情,因此您不必到处搜索它们。使用easyGUI,您必须滚动您自己的函数调用。

def call_function():
    print "call function executed"

choices=('MoveFwd', 'MoveBwd', "Call Function")
value=choicebox('Robot Moving', ' ', choices)
print "value =", value
if value==choices[2]:
    call_function()
else:
    print "nothing called"
于 2015-11-05T04:17:04.113 回答