- 首先在项目下创建一个lib文件夹–新建py文件:webui.py:
import tkinter
from tkinter import *
def tkintershow(textshow):
window = tkinter.Tk()
#所创建窗口的标题
window.title('窗口')
#所创建窗口的宽高
width = 800
height = 260
#所创建窗口居中显示
screenwidth = window.winfo_screenwidth()
screenheight = window.winfo_screenheight()
alignstr = '%dx%d+%d+%d' % (width, height, (screenwidth - width) / 2, (screenheight - height) / 2)
window.geometry(alignstr)
#所创建窗口增加文字标签并居中显示
Label(window,text=textshow,justify=LEFT,bg='white',font=('microsoft yahei', 16),width=300,height=300).pack(side='left')
#弹出窗口显示5秒后自动销毁
window.after(5000, window.destroy)
window.mainloop()
sleep(1)
return textshow
from tkinter import *
import tkinter
from lib.webui import *
from lib import webui
tkintershow('首页预览')
- 窗口效果预览