pythonV1V2/第30讲谁的恶作剧/课堂成果/课后作业-弹窗木马.py
sairate 7df250638d chore: 添加项目基础结构和示例代码
- 创建 .idea 目录和相关配置文件,设置项目结构
- 添加多个课堂成果示例代码,涵盖不同主题和功能
- 创建和配置 .gitignore 文件,忽略特定文件和目录
2025-07-05 09:36:00 +08:00

40 lines
1.5 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'''【课后作业要求】
弹窗木马
模拟本节课作品,完成视频中的轰炸效果。标签文字、颜色可以自定义。
提示:
想要设置标签文字颜色,
可以使用 fg='''''
import tkinter as tk # 导入tkinter库
import random # 导入随机库
import threading # 导入threading库用于创建和管理线程
import time # 导入时间库
def tanchuang():
root = tk.Tk() # 创建窗口对象
width = root.winfo_screenwidth() # 获取屏幕的宽度
height = root.winfo_screenheight() # 获取屏幕的高度
x = random.randint(0, width) # 随机生成的宽度
y = random.randint(0, height) # 随机生成的高度
root.title('恶作剧') # 定义窗口的标题
root.geometry(f"400x100+{x}+{y}") # 设置窗口的尺寸、位置
tk.Label(root,
text='Error!', # 显示文字
bg='black', # 背景颜色
fg='red', # 标签字体颜色
font=('楷体', 25), # 字体和字体大小
width=40, height=4 # 标签长宽
).pack() # 配置标签位置
root.mainloop()
for i in range(100): # 需要的弹框数量,根据自己需要来修改
# 创建一个线程对象将tanchuang函数作为目标函数
t = threading.Thread(target=tanchuang)
# 使主线程暂停0.1秒,以延迟新线程的启动。确保窗口不是同时出现,有一定间隔
time.sleep(0.1)
# 启动线程调用dow函数并创建一个新弹出窗口
t.start()