Tkinter - Preload window?

后端 未结 4 678
死守一世寂寞
死守一世寂寞 2021-01-01 02:57

I started building a python tkinter gui, the problem is, after adding many features to the gui, the loading started looking really ugly. When starting the m

4条回答
  •  温柔的废话
    2021-01-01 03:26

    The short answer is yes. You can set the window to appear as though you can't see it. Perform any code that takes time, and then display the window.

    Here's how:

    class MyTkRoot(tk.Tk):
        def __init__(self):
            tk.Tk.__init__(self)
            self.attributes('-alpha', 0.0)  # make window transparent
            # build gui...
            self.after(0, self.attributes, "-alpha", 1.0)  # back to normal
    root = MyTkRoot()
    root.mainloop()
    

    Here's a reference to the code with the example of a Toplevel. It will also work with the root however.

提交回复
热议问题