Python使用pycharm實(shí)現(xiàn)無限彈窗程序
運(yùn)行環(huán)境
PyCharm 2023.2.1
python3.11
具體內(nèi)容
源代碼
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) # 用戶不可關(guān)閉彈窗一 self.common_style = {"font": ("華文新魏", 14)} self.label = tk.Label(self.root, text="恭喜你打開了這個(gè)程序", **self.common_style, fg="red") self.label.pack(pady=20) self.close_program_button = tk.Button(self.root, text="關(guān)閉程序", 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 = [] # 存儲(chǔ)已存在彈窗的位置信息 self.generate_popup() def generate_popup(self): if self.popup_count < 20: popup = tk.Toplevel(self.root) popup.title("無限彈窗") popup.geometry("200x120") # 檢查已存在彈窗的位置,設(shè)置新彈窗的位置 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): # 計(jì)算新彈窗的位置,避免重疊 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 # 存儲(chǔ)新彈窗的位置信息 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") # 檢查已存在彈窗的位置,設(shè)置新彈窗的位置 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"你不會(huì)覺得點(diǎn)了 {self.detox_attempts} 次就有用吧") else: messagebox.showinfo("沒想到啊", f"你居然堅(jiān)持點(diǎn)了 {self.detox_attempts}次") self.root.destroy() if __name__ == "__main__": popup_generator = PopupGenerator() popup_generator.root.mainloop()
運(yùn)行結(jié)果
如下圖
點(diǎn)擊運(yùn)行時(shí)
點(diǎn)擊關(guān)閉程序按鈕(未點(diǎn)擊足夠次數(shù))
點(diǎn)擊關(guān)閉程序按鈕(點(diǎn)擊次數(shù)足夠)
關(guān)閉多試一下彈窗(僅并沒有用彈窗可關(guān)閉)
關(guān)閉程序的方法
1、任務(wù)管理器結(jié)束任務(wù)
2、點(diǎn)擊足夠次數(shù)的關(guān)閉程序
注意事項(xiàng)
1、沒有什么技術(shù)含量,僅娛樂使用
到此這篇關(guān)于Python使用pycharm實(shí)現(xiàn)無限彈窗程序的文章就介紹到這了,更多相關(guān)Python pycharm無限彈窗內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
python錄音并調(diào)用百度語音識(shí)別接口的示例
這篇文章主要介紹了python錄音并調(diào)用百度語音識(shí)別接口的示例,幫助大家更好的理解和利用python處理音頻,感興趣的朋友可以了解下2020-12-12Django開發(fā)RESTful API實(shí)現(xiàn)增刪改查(入門級(jí))
這篇文章主要介紹了Django開發(fā)RESTful API實(shí)現(xiàn)增刪改查(入門級(jí)),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-05-05Python的for和break循環(huán)結(jié)構(gòu)中使用else語句的技巧
平時(shí)我們把在if結(jié)構(gòu)中使用else語句當(dāng)作理所當(dāng)然,然而,Python強(qiáng)大的語法糖可以讓else語句在for和while循環(huán)中使用!下面我們就通過例子來看一下Python的for和break循環(huán)結(jié)構(gòu)中使用else語句的技巧2016-05-05Python Numpy 自然數(shù)填充數(shù)組的實(shí)現(xiàn)
今天小編就為大家分享一篇Python Numpy 自然數(shù)填充數(shù)組的實(shí)現(xiàn),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-11-11PyCharm刷新項(xiàng)目(文件)目錄的實(shí)現(xiàn)
今天小編就為大家分享一篇PyCharm刷新項(xiàng)目(文件)目錄的實(shí)現(xiàn),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-02-02Python實(shí)現(xiàn)簡(jiǎn)單的文件傳輸與MySQL備份的腳本分享
這篇文章主要介紹了Python實(shí)現(xiàn)簡(jiǎn)單的文件傳輸與MySQL備份的腳本分享,用到了socket與tarfile模塊,需要的朋友可以參考下2016-01-01