สมมติว่าเราต้องการสร้างหน้าจอเริ่มต้นโดยใช้ tkinter ในการสร้างหน้าจอ asplash เราจะทำตามขั้นตอนด้านล่าง -
-
สร้างหน้าจอสแปลชพร้อมป้ายกำกับบางส่วน
-
ทำให้หน้าจอเริ่มต้นไร้ขอบโดยใช้ overrideredirect วิธีการ
-
สร้างฟังก์ชันสำหรับหน้าต่างหลักซึ่งจะปรากฏขึ้นชั่วขณะหลังจากหน้าจอเริ่มต้น
-
ตอนนี้ใช้ หลัง เราสามารถกำหนดเวลาที่หน้าต่างหลักจะปรากฏขึ้นได้
ตัวอย่าง
#Importing the tkinter library
from tkinter import *
#Create an instance of tkinter frame
splash_win= Tk()
#Set the title of the window
splash_win.title("Splash Screen Example")
#Define the size of the window or frame
splash_win.geometry("700x200")
#Remove border of the splash Window
splash_win.overrideredirect(True)
#Define the label of the window
splash_label= Label(splash_win, text= "Hello World!", fg= "green",
font= ('Times New Roman', 40)).pack(pady=20)
def mainWin():
splash_win.destroy()
win= Tk()
win.title("Main Window")
win.geometry("700x200")
win_label= Label(win, text= "Main Window", font= ('Helvetica', 25), fg= "red").pack(pady=20)
#Splash Window Timer
splash_win.after(5000, mainWin)
mainloop() การเรียกใช้โค้ดด้านบนจะสร้างเอาต์พุตและจะแสดงหน้าจอสแปลชและหน้าต่างหลักหลังจากนั้นครู่หนึ่ง
ผลลัพธ์

