2015-11-05 40 views
1

我想用buttonBox(来自Python easyGUI)在Python中触发函数。但我不知道该怎么做。 的buttonbox代码是这样的:如何使用buttonBox来触发脚本?

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() 

然后我的问题是,如何将这两个联系在一起?

回答

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"