创建一个;“无模式”;使用tkinter的窗口

创建一个;“无模式”;使用tkinter的窗口,tkinter,Tkinter,我是一名python/tkinter新手,正在努力让一个“无模式窗口”出现在我的根画布前,同时完成一些工作,然后以编程方式关闭它 我们已经花了好几天的时间试图了解如何做到这一点。在我使用的RAD工具中,它只有一行代码,所以我肯定是超出了我的深度 from tkinter import * from functools import partial import time # creating tkinter window root = Tk() root.overrideredirect

我是一名python/tkinter新手,正在努力让一个“无模式窗口”出现在我的根画布前,同时完成一些工作,然后以编程方式关闭它

我们已经花了好几天的时间试图了解如何做到这一点。在我使用的RAD工具中,它只有一行代码,所以我肯定是超出了我的深度

from tkinter import * 
from functools import partial
import time

# creating tkinter window 
root = Tk() 
root.overrideredirect(True)

#Define variables

HomeDir = "/temp/" #Home Directory for images etc

# Creating a photoimage object to use on main canvas button 

photo1 = PhotoImage(file = HomeDir + "B1.gif") 

#Create and populate the canvas

w = Canvas(root, width=1024, height=680, highlightthickness=0)
BackgroundImage = PhotoImage(file = HomeDir + "BackGroundImage.gif")
BackgroundCreated = w.create_image((0,0), image=BackgroundImage, anchor=NW)
TopMsg = w.create_text((320, 20), text="TEST", font="MSGothic 30 bold", anchor=NW)
w.pack(side = "bottom", fill = "both", expand = "no")

#Define button actions

def ButtonAction(BN):
    print("Button " + str(BN)) # For debug purposes

    #At this point I want a modeless "Window" to pop up with an image and 
    #some text on it such as "Button X Clicked"
    #and then after a few seconds I want the "Window" to close automatically


# Adding widgets to the root window 

B1 = Button(root, image = photo1, command=partial(ButtonAction,1)).place(x=100,y=300) 


mainloop()
从代码中,我尝试创建def按钮操作(BN):执行以下操作:

在根画布前面弹出一个较小的“无模式窗口”,这样我就可以显示“请稍候…”之类的内容以及填充整个窗口的图像

做一些工作,所以我们尝试使用睡眠来模拟这一点,以暂停操作一段时间

关闭无模式窗口并再次返回主画布


我不会发布我的任何努力,因为我认为我完全弄错了。

您需要做的就是创建一个
顶级
的实例,然后在其中放入您想要的任何小部件<代码>顶级默认情况下,窗口是无模式的

要在一段时间后消除它,可以使用
after
。它看起来像这样:

def ButtonAction(BN):
    top = Toplevel(root)
    label = Label(top, text="Button {} clicked".format(BN))
    label.pack(padx=20, pady=20)

    top.after(5000, top.destroy)

非常感谢你,它的工作原理和它应该做的一样,比我尝试的任何东西都简单