我在树莓派上使用 python 2.7 tkinter gui 来自动化一些材料测试。对于测试,必须测试多个样品,并且更换样品需要时间。我想提示文本说“请插入样本,然后按键盘上的输入”,并让功能暂停,直到按下输入。除了按回车,我还可以使用 tkinter 按钮。不使用外部库的任何想法?我尝试了一个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