import tkinter as tk |
import random |
import threading # 使用多线程 |
import time |
import functions |
def dow(): |
color_list = functions.colors() |
font_list = [ '黑体' , '宋体' , '仿宋' , '微软雅黑' , '楷体' , '隶书' , '华文琥珀' , '幼圆' , '华文行楷' , '新宋体' ] |
text_list = functions.blesses() |
window = tk.Tk() |
width = window.winfo_screenwidth() |
height = window.winfo_screenheight() |
a = random.randrange( 0 , width) |
b = random.randrange( 0 , height) |
window.title( '来自https://yuncode.net/python-tech的祝福' ) |
window.geometry( "280x100" + "+" + str (a) + "+" + str (b)) |
tk.Label(window, |
text = random.sample(text_list, 1 ), # 标签的文字 |
bg = random.sample(color_list, 1 ), # 背景颜色 |
font = (random.sample(font_list, 1 ), 17 ), # 字体和字体大小 |
width = 20 , height = 20 # 标签长宽 |
).pack() # 固定窗口位置 |
window.mainloop() |
def bless(x): |
threads = [] |
for i in range (x): # 需要的弹框数量 |
t = threading.Thread(target = dow) |
threads.append(t) |
time.sleep( 0.1 ) |
threads[i].start() |
def main(): |
num = int ( input ( '请输入需要的祝福数量:' )) |
bless(num) |
if __name__ = = '__main__' : |
main() |
高级设计师
by: Python自学 发表于:2022-11-09 02:57:11 顶(0) | 踩(0) 回复
回复评论