Related Articles

Related Articles

How to create a Splash Screen using Tkinter?
  • Last Updated : 01 Nov, 2020

Prerequisite: Python GUI – tkinter

Python offers multiple options for developing a GUI (Graphical User Interface). Out of all the GUI methods, tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python.

What is a Splash Screen?

A splash screen in tkinter is a tkinter window that disappears after a fixed period and then a particular operation takes place. To Create a splash screen we will use after() and destroy() method.

  • The after() method assigns a time period (as argument) after which a particular operation takes place, that operation is transformed into a function and is passed as an argument in after() method.

Syntax:

root.after(time in millisecond, function name)
  • The destroy() method is used to close the current tkinter window.

Syntax:



root.destroy()

Below is a program that creates two normal Tkinter windows. The smaller window acts as a splash screen but it will not disappear.

Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# Import module
from tkinter import *
  
# Create object
splash_root = Tk()
  
# Adjust size
splash_root.geometry("200x200")
  
# Set Label
splash_label = Label(splash_root, text="Splash Screen", font=18)
splash_label.pack()
  
# main window function
def main():
    # Create object
    root = Tk()
  
    # Adjust size
    root.geometry("400x400")
  
  
# Call main function
main()
  
# Execute tkinter
mainloop()

chevron_right


Output:

Main Window

Splash Window

Now we will use the below methods:

  • destroy()
  • after()

To create a splash screen in tkinter.

Below is a program that creates Splash screen in tkinter using after() and destroy() methods.

Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# Import module 
from tkinter import *
    
# Create object 
splash_root = Tk() 
    
# Adjust size 
splash_root.geometry("200x200")
  
# Set Label
splash_label = Label(splash_root,text="Splash Screen",font=18)
splash_label.pack()
  
# main window function
def main():  
    # destory splash window
    splash_root.destroy()
  
    # Execute tkinter 
    root = Tk() 
        
    # Adjust size 
    root.geometry("400x400"
  
# Set Interval
splash_root.after(3000,main)
  
# Execute tkinter 
mainloop()

chevron_right


Output:

Here a splash screen is created and it stays for a particular time period and then a next operation takes place i.e a new window is generated.

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.




My Personal Notes arrow_drop_up
Recommended Articles
Page :