1

I have made a GUI using Tkinter for my Python script for a Voice Assistant. It is working pretty well. But I want to add an animation window to display an animation that I have created using After Effects as an intro to the app. I want it to open without the default close(x), maximize and minimize buttons. The window should stay till the animation is completed, and then it would disappear. The main window would then open normally to launch the GUI. To disable the close, maximize and minimize buttons I have used the root.overrideredirect(True) method. But I am not being able to simultaneously open the two windows one after the other as mentioned. I would be highly obliged if somebody would help me out with this! I have tested it with a code on a simple GUI. I am providing the code below for help with the problem!

from tkinter import *
import time

root = Tk()
root.geometry('500x300')
root.overrideredirect(True) # To disable the default Window decoration
time.sleep(5) # Assuming that the animation runs for 5 seconds
root.destroy() # This window destroys after being on screen for 5 seconds
root.mainloop()

root2 = Tk() # After the previous window is destroyed, this window opens up. Assume that this is the main window
root2.geometry('500x300')
root.mainloop()

Please help me out!

1 Answers1

1

The thing you call "animation window" is actually called "splash". There is a way to do what you want. You need to create a root window for the app (a Tk instance), and then you should hide (root.withdraw()) it. Now create a Toplevel for the splash, wait for 5 seconds, destroy it, and show (root.deiconify()) the Tk window again.

Note: time.sleep(5) should never be used with Tkinter, use root.after(ms, func) instead.

from tkinter import *


def show_splash():
    splash = Toplevel()
    splash.geometry('500x300')
    splash.overrideredirect(True) # To disable the default Window decoration
    splash.after(5000, splash.destroy) # This window destroys after being on screen for 5 seconds
    splash.wait_window()

root = Tk()
root.withdraw()
show_splash()
root.deiconify()
root.mainloop()

PS: Procedural programming is not a good idea for pretty complex Tkinter-based apps. You should consider using OOP instead.

PPS: Take a look at this and this answers.

Demian Wolf
  • 1,698
  • 2
  • 14
  • 34
  • 1
    I checked using your code. It worked fine on the test code. But I need to be sure if it works on the main one. I will let you know once I am done! Thanks for your help! – Soham Chatterjee May 30 '20 at 15:03
  • @SohamChatterjee I have found a shorter, simpler and cleaner way to do what you're trying to, so I've updated the code in the answer. Check it out. – Demian Wolf May 30 '20 at 15:22