2

I have created a working GUI interface using Tkinter, Python. It takes a minuet or two to load the GUI, my question is the following:

Is there away to display an image while python is performing the load on the GUI?

Really appreciate the help.

aBiologist
  • 2,007
  • 2
  • 14
  • 21
  • You could potentially spawn a new TopLevel which has an image on it. I have to wonder why your GUI takes so long to load though. – scotty3785 Nov 23 '16 at 13:16
  • @scotty3785, it takes about 10 seconds to display the GUI, however, when I use pyinstaller to package the GUI and use it for another machine "I am using Windows" which doesn't have python install, it takes a minuet or so to display it , any idea? – aBiologist Nov 23 '16 at 13:26
  • Just display another, simpler UI (with just the image) before starting to load the real UI? – tobias_k Nov 23 '16 at 13:31
  • Did that, thanks, now how to not include the tool bar as I want only the image ? – aBiologist Nov 23 '16 at 13:36

1 Answers1

2

As suggested in the comments you can use a TopLevel to display another window. You can use <NameOfYourTopLevel>.overrideredirect(1) to hide the window frame.

You might also consider using .after_idle(<callback>) to close the window once the GUI has completed loading.

Here is more complete example. I haven't been able to replicate the large delay in drawing the GUI so have simulated this with self.after(5000,self.splash.destroy). You should be able to replace this with self.after_idle(self.splash.destroy)

try:
    import tkinter as tk
except:
    import Tkinter as tk


class App(tk.Frame):
    def __init__(self,master=None,**kw):
        self.splash = Splash(root)
        tk.Frame.__init__(self,master=master,**kw)
        tk.Label(self,text="MainFrame").grid()
        self.after(5000,self.splash.destroy)

class Splash(tk.Toplevel):
    def __init__(self,master=None,**kw):
        tk.Toplevel.__init__(self,master=master,**kw)
        tk.Label(self,text="Show Image here").grid()
        self.overrideredirect(1)

if __name__ == '__main__':
    root = tk.Tk()

    App(root).grid()
    root.mainloop()

This question will tell you how to centre the window in your screen.

Community
  • 1
  • 1
scotty3785
  • 6,763
  • 1
  • 25
  • 35