python tkinter 事件_暂停python tkinter中的事件

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

解决方案import Tkinter

import tkMessageBox

print "Sample #1"

tkMessageBox.showinfo("Message", "Insert sample and press OK")

print "Sample #2"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值