From 1d6b0b4b019d2f729186ba22f7a569fbf20baf35 Mon Sep 17 00:00:00 2001 From: Zhao Zuohong <1040110848@qq.com> Date: Mon, 15 Nov 2021 17:42:49 +0800 Subject: [PATCH] first commit --- main.py | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 main.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..503ef35 --- /dev/null +++ b/main.py @@ -0,0 +1,56 @@ +import tkinter as tk +import tkinter.ttk as ttk +import tkinter.messagebox as mb + + +def quit_school(): + mb.showinfo("退学通知", "滴!你被退学了!") + + +root = tk.Tk(className="你 要 挂 科 了") +root.geometry("400x200") +l = ttk.Label(root, text="可爱的小小小梦蕾要~挂~科~了~!", font=("微软雅黑", 14)) +l.place(x=30, y=30, width=340) + +by = ttk.Button(root, text="是的", command=quit_school) +by.place(x=160, y=140, width=100, height=40) +bn = ttk.Button(root, text="不是") +bn.place(x=280, y=140, width=100, height=40) + +state = 0 + + +def exchange(): + if state == 0: + by.place(x=280, y=140, width=100, height=40) + bn.place(x=160, y=140, width=100, height=40) + else: + by.place(x=160, y=140, width=100, height=40) + bn.place(x=280, y=140, width=100, height=40) + + +def vertical_move(): + if state == 2: + bn.place(x=280, y=100, width=100, height=40) + else: + bn.place(x=280, y=140, width=100, height=40) + + +def on_hover(_): + global state + if state in [0, 1]: + exchange() + else: + vertical_move() + state = (state + 1) % 4 + + +def on_closing(): + mb.showinfo("提示", "关闭窗口也改变不了你挂科的事实!") + root.destroy() + + +bn.bind("", on_hover) +root.protocol("WM_DELETE_WINDOW", on_closing) + +root.mainloop()