我想通过制作一个不断显示警告的脚本来恶作剧我的朋友,并且完全无法关闭。到目前为止我的代码是:
import tkinter as tk
from tkinter import messagebox
import random
root = tk.Tk()
messages=["Anodr settlument neds yer hulp!","Another settlement needs your help!",
"Settlument another help needs!","Need hulp settlement!","Anuthr settlumet neeedl yur halp!"]
def on_closing():
pass
root.protocol("WM_DELETE_WINDOW", on_closing)
while True(5):
messagebox.showwarning("Prstn",messages[random.randint(0,4)])
root.mainloop()
问题是,如果你关闭CMD窗口,它仍然可以关闭,当你启动程序时它会打开。我怎么能抵消这个?如果没有解决方案,我该如何调整我的程序,以便它一次显示一堆警告,这会淹没你的屏幕?
答案 0 :(得分:-2)
将消息变成一个问题,然后继续问愚蠢的问题......不推荐,但他们可能不再是你的朋友了。
yn = tkMessageBox.askyesno("Text", "Ask a question...")
if yn == True:
yn = tkMessageBox.askyesno("Text", "Ask another question...")
if yn == True:
yn = tkMessageBox.askyesno("Text", "Ask another question...")
...
...
else:
yn = tkMessageBox.askyesno("Text", "Ask another question...")
if yn == True:
yn = tkMessageBox.askyesno("Text", "Ask another question...")
else:
...
...