import random
import tkinter as tk
def shu():
t.insert(tk.INSERT, '很遗憾,你输了\n')
def ying():
t.insert(tk.INSERT, '恭喜你,赢了\n')
def ping():
t.insert(tk.INSERT, '平局\n')
def jiandao():
cpt = random.randint(0, 2)
t.delete(0.0, tk.END)
t.insert(tk.INSERT, '电脑为:' + data[cpt] + '\n')
if cpt == 0:
shu()
elif cpt == 1:
ping()
else:
ying()
def shitou():
cpt = random.randint(0, 2)
t.delete(0.0, tk.END)
t.insert(tk.INSERT, '电脑为:' + data[cpt] + '\n')
if cpt == 0:
ping()
elif cpt == 1:
ying()
else:
shu()
def bu():
cpt = random.randint(0, 2)
t.delete(0.0, tk.END)
t.insert(tk.INSERT, '电脑为:' + data[cpt] + '\n')
if cpt == 0:
ying()
elif cpt == 1:
shu()
else:
ping()
def qui():
win.destroy()
data = ['石头', '剪刀', '布']
win = tk.Tk()
win.geometry('300x300+300+300')
win.title("剪刀石头布游戏")
l = tk.Label(win, text='你好!欢迎来到猜拳游戏', bg='green', width=30, height=2).pack()
t = tk.Text(win, height=3)
t.pack()
b1 = tk.Button(win, text='剪刀', font=('Arial', 12), width=10, height=1, command=jiandao)
b1.pack()
b2 = tk.Button(win, text='石头', font=('Arial', 12), width=10, height=1, command=shitou)
b2.pack()
b3 = tk.Button(win, text='布', font=('Arial', 12), width=10, height=1, command=bu)
b3.pack()
b4 = tk.Button(win, text='退出', font=('Arial', 12), width=10, height=1, command=qui)
b4.pack()
win.mainloop()
if __name__ == "__main__":
pass