I am using a python 2.7 tkinter gui on a raspberry pi to automate some material testing. For the testing, multiple samples must be tested and it takes time to swap out the samples. I want to prompt text saying something like "Please insert sample one then press enter on keyboard" and have the function pause until enter has been pressed. Instead of pressing enter I could also use a tkinter button. Any ideas without using external libraries? I have tried a while loop in which I try and exit the loop once a button is pressed, but since the loop is running the button does not register.
Sample code (removed lots of code and left what is relevant):
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
Use tkMessageBox
Here's a working example that uses a callback to start the test, and a callback to advance each sample.