- 创建 .idea 目录和相关配置文件,设置项目结构 - 添加多个课堂成果示例代码,涵盖不同主题和功能 - 创建和配置 .gitignore 文件,忽略特定文件和目录
26 lines
1.0 KiB
Python
26 lines
1.0 KiB
Python
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()
|