Tkinter 是 Python 的标准 GUI 库。Python 使用 Tkinter 可以快速的创建 GUI 应用程序。由于 Tkinter 是内置到 python 的安装包中、只要安装好 Python 之后就能 import Tkinter 库、而且 IDLE 也是用 Tkinter 编写而成、对于简单的图形界面 Tkinter 还是能应付自如。
效果:
源码:
import tkinter as tk
import random
import threading
def run():
window = tk.Tk()
width = window.winfo_screenwidth()
height = window.winfo_screenheight()
a = random.randrange(0, width)
b = random.randrange(0, height)
window.title('中秋快乐')
window.geometry("200x50" + "+" + str(a) + "+" + str(b))
tk.Label(window,
text='中秋快乐!', # 标签的文字
bg='#CD7F32', # 背景颜色
font=('楷体', 17), # 字体和字体大小
width=15, height=2 # 标签长宽
).pack() # 固定窗口位置
window.mainloop()
threads = []
for i in range(68): # 需要的弹框数量
t = threading.Thread(target=run)
threads.append(t)
threads[i].start()
网友评论