import tkinter as tk
import random

# 主窗口
root = tk.Tk()
root.title("石头剪刀布")
root.geometry("420x340")

# 游戏数据
options = ["石头", "剪刀", "布"]
player_text = tk.StringVar(value="你的选择：暂无")
pc_text = tk.StringVar(value="电脑选择：暂无")
result_text = tk.StringVar(value="等待出招")

def game_choose(player_act):
    pc_act = random.choice(options)
    player_text.set(f"你的选择：{player_act}")
    pc_text.set(f"电脑选择：{pc_act}")

    # 判断胜负逻辑
    if player_act == pc_act:
        res = "⚖️ 平局"
    elif (player_act == "石头" and pc_act == "剪刀") or \
         (player_act == "剪刀" and pc_act == "布") or \
         (player_act == "布" and pc_act == "石头"):
        res = "🎉 你赢了！"
    else:
        res = "😥 你输了！"
    result_text.set(f"本局结果：{res}")

# 界面组件
tk.Label(root, textvariable=player_text, font=("SimHei", 14)).pack(pady=6)
tk.Label(root, textvariable=pc_text, font=("SimHei", 14)).pack(pady=6)
tk.Label(root, textvariable=result_text, font=("SimHei",16,"bold"), fg="#d02020").pack(pady=12)

btn_frame = tk.Frame(root)
btn_frame.pack(pady=10)

# 三个出招按钮
tk.Button(btn_frame, text="石头", width=8, font=("SimHei",12), command=lambda: game_choose("石头")).grid(row=0, column=0, padx=4)
tk.Button(btn_frame, text="剪刀", width=8, font=("SimHei",12), command=lambda: game_choose("剪刀")).grid(row=0, column=1, padx=4)
tk.Button(btn_frame, text="布", width=8, font=("SimHei",12), command=lambda: game_choose("布")).grid(row=0, column=2, padx=4)

# 退出按钮
tk.Button(root, text="关闭游戏", font=("SimHei",12), command=root.destroy).pack(pady=20)

root.mainloop()
