Python实现多重弹窗脚本 整蛊朋友

bat批处理的弹窗脚本看到过了很多篇
今天来用Python实现一下多重弹窗
主要用的是多线程和Python的tkinterGUI实现

实现思路:
使用多线程,每个线程挂载一个tk窗口,进而实现了多重弹窗
用random库随机弹窗的位置

import tkinter as tk
import random
import threading
import time


def dow():
    window = tk.Tk()
    window.title('你是憨憨')
    window.geometry("200x50" + "+" + str(random.randrange(0, window.winfo_screenwidth())) + "+" + str(random.randrange(0, window.winfo_screenheight())))
    tk.Label(window,
             text='你是个铁憨憨!',  # 标签的文字
             bg='Red',  # 背景颜色
             font=('楷体', 17),  # 字体和字体大小
             width=20, height=2  # 标签长宽
             ).pack()  # 固定窗口位置
    window.mainloop()


threads = []
# while True:  #这句为死循环,无限弹窗
for i in range(100):  # 需要的弹框数量
    t = threading.Thread(target=dow)
    threads.append(t)
    time.sleep(0.1)
    threads[i].start()

效果图如下:
效果图

一起学习python,小白指导,教学分享记得私信我

猜你喜欢

转载自blog.csdn.net/Miku_wx/article/details/111880835