tkinter 在 mainloop() 之后没有任何运行 [英] tkinter nothing runs after mainloop()

查看:65
本文介绍了tkinter 在 mainloop() 之后没有任何运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我正在创建一个小图形用户界面,用于指导用户配置设备.您运行程序,选择所需的配置,然后它会将您发送到另一个窗口,在该窗口中您会收到有关如何设置设备以便从您的计算机(通过串行)运行测试的说明.虽然它以前工作过,但有些事情发生了变化,我无法弄清楚是什么.这是我对相关窗口的代码.所有文件路径都是正确的.运行串行配置的程序有效.我已经将问题缩小到它不会在 mainloop() 之外运行测试的地方.选择运行配置时,将弹出问题的此窗口,同时它应该开始运行配置.SLICE_SETUP"是实际的配置类,SLICE"是测试本身.

Currently I am creating a small GUI that guides a user through a configuration of a piece of equipment. You run the program, you select the desired configuration and it sends you to another window in which you receive directions on how to set up the piece of equipment in order to run the test from your computer (via serial). While it was working before, something has changed and I can't figure out what. This is my code for the window in question. all file paths are correct. the program which runs the serial configuration works. I have narrowed down the issue to where it will not run the test outside of mainloop(). When selecting to run the configuration, this window in question will pop up, and at the same time it should start running the configuration. "SLICE_SETUP" is the actual config class and "SLICE" is the test itself.

import sys
from Tkinter import *
from slice_setup import SLICE_SETUP
obj_rcs = SLICE_SETUP()

class pleasewait:

    def pleasewaitbox(self):
        pGui = Tk()
        pGui.geometry("300x100+400+250")
        pGui.title("RSAM BCT")
        plabel = Label(pGui, text= "REDCOM SLICE", fg="red").pack()
        plabel2 = Label(pGui, text= "BCT - Basic Configuration Test", fg= "red").pack()
        plabel3 = Label(pGui, text= "Please wait...", fg= "black").place(x = 120, y = 50)
        plabel3 = Label(pGui, text= "Estimated time: 3 min 6 sec", 
        fg= "black").place(x = 80, y = 70)
        pGui.mainloop()
        obj_rcs.SLICE()

obj_wait = pleasewait()
obj_wait.pleasewaitbox()

推荐答案

除非 mainloop() 在它自己的线程/进程中运行,否则你将无法在它之外做任何事情,直到主窗口被破坏.请参阅https://stackoverflow.com/a/8685760/138772

Unless mainloop() runs in its own thread/process, you won't be able to do anything outside of it until the main window is destroyed. See https://stackoverflow.com/a/8685760/138772

我的建议是将一个方法绑定到 pGuiActivate 事件,该事件将调用 obj_rcs.SLICE() 然后解除绑定自身来自 gui 以便它不会在每次更改窗口焦点时运行.(在 pleasewait 类中使用标志变量也可以.)

My suggestion would be to bind a method to the Activate event for pGui that would call obj_rcs.SLICE() and then debind itself from the gui so that it isn't run every time window focus is changed. (Using a flag variable in your pleasewait class could work as well.)

这篇关于tkinter 在 mainloop() 之后没有任何运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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