如何使用 Tkinter 创建闪屏?
假设我们要使用 Tkinter 创建闪屏。若要创建一个闪屏,我们会按照以下步骤进行操作 −
创建一个闪屏,在其中添加一些标签。
使用 overrideredirect 方法,使闪屏变为无边框。
创建主窗口的函数,该函数会在闪屏出现一段时间后出现。
现在使用 after 方法,我们可以定义主窗口出现的时间。
示例
#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()运行以上代码将生成输出,并且会显示闪屏,一段时间后,再显示主窗口。
输出


广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP