article

Wednesday, April 5, 2023

Python Tkinter Loading Screen - Splash Screen

Python Tkinter Loading Screen - Splash Screen

loadingscreen/loading.py
 
#loadingscreen/loading.py
from tkinter import *
from tkinter.ttk import Progressbar
import sys
import home
import os

root = Tk()
# root.resizable(0, 0)
image = PhotoImage(file='images\\loading.png')

height = 653
width = 736
x = (root.winfo_screenwidth()//2)-(width//2)
y = (root.winfo_screenheight()//2)-(height//2)
root.geometry('{}x{}+{}+{}'.format(width, height, x, y))
root.overrideredirect(1)

root.wm_attributes('-topmost', True)
root.lift()
root.wm_attributes("-topmost", True)
root.wm_attributes("-disabled", True)
root.wm_attributes("-transparentcolor", "white")

bg_label = Label(root, image=image, bg='white')
bg_label.place(x=0, y=0)

progress_label = Label(root, text="Please Wait...", font=('Comic Sans MS', 13, 'bold'), fg='#14183e', bg='#71b3ef')
progress_label.place(x=190, y=430)
progress = Progressbar(root, orient=HORIZONTAL, length=360, mode='determinate')
progress.place(x=190, y=480)

def top():
    root.withdraw()
    os.system("python home.py")
    root.destroy()


i = 0


def load():
    global i
    if i <= 10:
        txt = 'Please Wait...  ' + (str(10*i)+'%')
        progress_label.config(text=txt)
        progress_label.after(1000, load)
        progress['value'] = 10*i
        i += 1
    else:
        top()

load()

root.mainloop()
loadingscreen/home.py
 
#loadingscreen/home.py
from tkinter import *
from PIL import ImageTk, Image, ImageDraw
import sqlite3


class HomePage:
    def __init__(self, System_window):
        self.System_window = System_window

        # Window Size and Placement
        System_window.rowconfigure(0, weight=1)
        System_window.columnconfigure(0, weight=1)
        height = 650
        width = 700
        x = (System_window.winfo_screenwidth()//2)-(width//2)
        y = (System_window.winfo_screenheight()//4)-(height//4)
        System_window.geometry('{}x{}+{}+{}'.format(width, height, x, y))
        System_window.resizable(0, 0)

        # window Icon
        icon = PhotoImage(file='images\\logo.png')
        System_window.iconphoto(True, icon)

        System_window.title('Inventory System')

        Label(System_window, text = "Username").place(x = 40,y = 60) 
           
        Label(System_window, text = "Password").place(x = 40, y = 100) 
           
        Button(System_window, text = "Submit").place(x = 40, y = 130)
           
        Entry(System_window, width = 30).place(x = 110, y = 60) 
           
        Entry(System_window, width = 30).place(x = 110, y = 100) 
        
def page():
    window = Tk()
    HomePage(window)
    window.mainloop()


if __name__ == '__main__':
    page()
download splash screen png file https://drive.google.com/file/d/1O9csuWnQfe60pqL5z12V_18ELDwqErOp/view?usp=share_link

Run PS C:\python_dev\tkinter\loadingscreen> python loading.py

Related Post