简体   繁体   English

python的Tkinter包的lift()方法不起作用

[英]lift() method of python's Tkinter package not working

I am trying to build an application with a main window, and a background thread that checks a certain condition in a loop, and when the condition is met, brings the main window to the front. 我正在尝试构建一个具有主窗口和后台线程的应用程序,该线程在循环中检查特定条件,并在满足条件时将主窗口置于最前面。 To bring the window to the front i use the lift() method, but it doesn't work. 为了将窗口置于最前面,我使用了lift()方法,但是它不起作用。 So I did the following experiment from the python command line: 因此,我从python命令行进行了以下实验:

from Tkinter import *
root = Tk()

A tk window appears. 出现一个tk窗口。 Minimize the window and then: 最小化窗口,然后:

root.lift()

Nothing happens. 什么都没发生。 I also tried start the window's mainloop before lifting: 我还尝试在举升之前启动窗口的主循环:

import thread
# start mainloop in separate thread so we can continue typing
thread.start_new_thread(root.mainloop, ())
root.lift()

Again, nothing happens. 同样,什么也没发生。 In my actual code it is even worse - once I call lift() , the window is stuck and stops responding. 在我的实际代码中,情况甚至更糟-一旦我调用lift() ,窗口就会被卡住并停止响应。

What am I doing wrong? 我究竟做错了什么?

(I'm using Python 2.7.2 on Windows 7.) (我在Windows 7上使用Python 2.7.2。)

You cannot run the mainloop in a thread different from the one where you create the widgets. 您不能在与创建小部件的线程不同的线程中运行mainloop。 In fact, you can't interact with widgets at all from another thread. 实际上,您根本无法从另一个线程与小部件进行交互。

To revert the effects of minimizing the window you need to use the deiconify method. 要恢复最小化窗口的效果,您需要使用deiconify方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM