def dow(): t = tk.Tk() width = t.winfo_screenwidth() height = t.winfo_screenheight() a = random.randrange(0, width) b = random.randrange(0, height) t.title('端午安康') t.geometry('200x50' + '+' + str(a) + '+' + str(b)) tk.Label(t, text='端午安康!', bg='Green', # 背景色 font=('楷体', 17), # 字体和字体大小 width=15, height=2 # 标签长宽 ).pack() t.mainloop() threads = [] for i in range(10): # 需要的弹框数量 t = threading.Thread(target=dow) threads.append(t) time.sleep(0.1) threads[i].start()
看一下效果:
![ba83221f00cdb3e05fdcfed042af400e.png](https://i-blog.csdnimg.cn/blog_migrate/b3970c513f1c6da6c861e2bbfa5e9038.png)
![90a0a35c894b06edb33dd77b03e46ea2.gif](https://i-blog.csdnimg.cn/blog_migrate/7ff800066d10fc478e3f234d1699d784.gif)