写着玩的程序:pycharm实现无限弹窗程序(非病毒程序,仅整蛊使用)

运行环境

PyCharm 2023.2.1

python3.11

具体内容

源代码

import tkinter as tk
from tkinter import messagebox
import threading

class PopupGenerator:
    def __init__(self):
        self.root = tk.Tk()
        self.root.geometry("200x120")
        self.root.title("无限弹窗")
        self.root.protocol("WM_DELETE_WINDOW", lambda: None)  # 用户不可关闭弹窗一
        self.common_style = {"font": ("华文新魏", 14)}
        self.label = tk.Label(self.root, text="恭喜你打开了这个程序", **self.common_style, fg="red")
        self.label.pack(pady=20)
        self.close_program_button = tk.Button(self.root, text="关闭程序", command=self.try_detox, **self.common_style,
                                              bg="green", fg="white")
        self.close_program_button.pack(pady=10)
        self.popup_count = 0
        self.detox_attempts = 0
        self.popup_positions = []  # 存储已存在弹窗的位置信息
        self.generate_popup()

    def generate_popup(self):
        if self.popup_count < 20:
            popup = tk.Toplevel(self.root)
            popup.title("无限弹窗")
            popup.geometry("200x120")
            # 检查已存在弹窗的位置,设置新弹窗的位置
            x, y = self.calculate_popup_position(popup.winfo_reqwidth(), popup.winfo_reqheight())
            popup.geometry(f"+{x}+{y}")
            popup_label = tk.Label(popup, text="多试一下", fg="blue", **self.common_style)
            popup_label.pack(pady=20)
            popup.protocol("WM_DELETE_WINDOW", self.on_popup_close)
            self.popup_count += 1
            threading.Timer(1, self.generate_popup).start()

    def calculate_popup_position(self, width, height):
        # 计算新弹窗的位置,避免重叠
        x_offset, y_offset = 25, 25
        x = self.root.winfo_x() + x_offset + len(self.popup_positions) * x_offset
        y = self.root.winfo_y() + y_offset + len(self.popup_positions) * y_offset
        # 存储新弹窗的位置信息
        self.popup_positions.append((x, y))
        return x, y

    def on_popup_close(self):
        self.generate_additional_popup()

    def generate_additional_popup(self):
        additional_popup = tk.Toplevel(self.root)
        additional_popup.title("无限弹窗")
        additional_popup.geometry("200x120")
        # 检查已存在弹窗的位置,设置新弹窗的位置
        x, y = self.calculate_popup_position(additional_popup.winfo_reqwidth(), additional_popup.winfo_reqheight())
        additional_popup.geometry(f"+{x}+{y}")
        additional_popup_label = tk.Label(additional_popup, text="并没有用", fg="purple", **self.common_style)
        additional_popup_label.pack(pady=20)

    def try_detox(self):
        self.detox_attempts += 1
        if self.detox_attempts <= 10:
            messagebox.showinfo("温馨提示", f"你不会觉得点了 {self.detox_attempts} 次就有用吧")
        else:
            messagebox.showinfo("没想到啊", f"你居然坚持点了 {self.detox_attempts}次")
            self.root.destroy()

if __name__ == "__main__":
    popup_generator = PopupGenerator()
    popup_generator.root.mainloop()

运行结果如图

点击运行时

点击关闭程序按钮(未点击足够次数)

点击关闭程序按钮(点击次数足够)

关闭多试一下弹窗(仅并没有用弹窗可关闭)

关闭程序的方法

1、任务管理器结束任务

2、点击足够次数的关闭程序

注意事项

1、没有什么技术含量,仅娱乐使用

相关推荐
小鹿( ﹡ˆoˆ﹡ )18 分钟前
探索IP协议的神秘面纱:Python中的网络通信
python·tcp/ip·php
卷心菜小温33 分钟前
【BUG】P-tuningv2微调ChatGLM2-6B时所踩的坑
python·深度学习·语言模型·nlp·bug
陈苏同学1 小时前
4. 将pycharm本地项目同步到(Linux)服务器上——深度学习·科研实践·从0到1
linux·服务器·ide·人工智能·python·深度学习·pycharm
唐家小妹1 小时前
介绍一款开源的 Modern GUI PySide6 / PyQt6的使用
python·pyqt
羊小猪~~2 小时前
深度学习项目----用LSTM模型预测股价(包含LSTM网络简介,代码数据均可下载)
pytorch·python·rnn·深度学习·机器学习·数据分析·lstm
Marst Code2 小时前
(Django)初步使用
后端·python·django
985小水博一枚呀2 小时前
【对于Python爬虫的理解】数据挖掘、信息聚合、价格监控、新闻爬取等,附代码。
爬虫·python·深度学习·数据挖掘
立秋67892 小时前
Python的defaultdict详解
服务器·windows·python
萧鼎3 小时前
Python第三方库选择与使用陷阱避免
开发语言·python
白拾3 小时前
使用Conda管理python环境的指南
开发语言·python·conda