import tkinter as tk import random def move_window(): # 移动窗口随机出现 x = random.randint(0, root.winfo_screenwidth() - 400) y = random.randint(0, root.winfo_screenheight() - 100) root.geometry("400x100"+"+"+str(x)+"+"+str(y)) def yes(): # 对方谅解 label.config(text="谢谢您的谅解!") root.after(1000, root.destroy) # 感谢谅解1秒后关闭窗口 root = tk.Tk() # 创建窗口对象 root.title("小米的忏悔") # 定义窗口的标题 root.geometry("400x100") # 设置窗口的尺寸 label = tk.Label(root, text="最近给大家添麻烦了,对不起!你们能够原谅我吗?") label.pack() # 配置标签 button_no = tk.Button(root, text="不原谅", bg = 'red', fg = 'white', command=move_window) button_no.pack() # 配置“不原谅”按钮 button_yes = tk.Button(root, text="原谅你吧!", bg = "green", fg = 'white', command=yes) button_yes.pack() # 配置“原谅”按钮 label = tk.Label(root, text="") label.pack() # 配置“感谢谅解”的标签 root.mainloop()