我在raspberry pi上使用Python2.7TkinterGUI来自动化一些材料测试。为了进行测试,必须测试多个样本,更换样本需要时间。我想要提示文本,比如“请插入示例一,然后按键盘上的enter键”,并让函数暂停,直到按下enter键。我也可以用一个tkinter按钮来代替按enter键。有没有不使用外部库的想法?我试过一个while循环,当一个按钮被按下时,我尝试退出循环,但是由于循环正在运行,所以按钮没有注册。在
示例代码(删除了大量代码并保留了相关内容):
class App:
def __init__(self,master):
#self.WILTRON = Wiltron_54128A_GPIB()
self.var = tk.StringVar()
self.var.trace("w",self.getTest)
self.okbutton = tk.IntVar()
self.okbutton.trace("w",self.OKbutton)
frame = Frame(master)
frame.pack()
#Initial GUI values
self.var.set('Choose Test')
testChoices = ['TEST']
App.testOption = tk.OptionMenu(frame, self.var, *testChoices)
App.testOption.grid(row=0, column=0)
okButton = tk.Button(frame, text=" OK ", command=self.OKbutton).grid(row=2, column=1)
#Test routine functions
def getTest(self, *args):
test = self.var.get()
sf = "IC Network Analyzer"
root.title(sf)
#####
if test == "TEST":
sample1 = self.WILTRON.Sample_Data()
print 'Change out sample then press OK'
#This is where I need to pause until the next sample has been inserted
sample2 = self.WILTRON.Sample_Data()
#ect.
#####
def OKbutton(self):
#Whatever I need to do to make the button exit the pause
使用tkMessageBox
下面是一个工作示例,它使用回调来启动测试,并使用回调来推进每个示例。
相关问题 更多 >
编程相关推荐