暂停python tkinter中的事件 [英] Pause for an event in python tkinter

查看:723
本文介绍了暂停python tkinter中的事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在树莓派上使用python 2.7 tkinter gui来自动化一些材料测试.对于测试,必须测试多个样本,并且交换出样本需要花费时间.我想提示一些类似请插入示例一,然后在键盘上按Enter"之类的文本,并使功能暂停,直到按Enter为止.除了按下Enter键,我还可以使用tkinter按钮.有没有使用外部库的想法吗?我尝试了一个while循环,在该循环中我尝试在按下按钮后退出该循环,但是由于该循环正在运行,因此该按钮无法注册.

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

推荐答案

使用 tkMessageBox

import Tkinter
import tkMessageBox

print "Sample #1"
tkMessageBox.showinfo("Message", "Insert sample and press OK")
print "Sample #2"

这篇关于暂停python tkinter中的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆