from tkinter import *
from tkinter.messagebox import *
import random
root = Tk()
label = Label(root, text='Rock Paper scissors')
label.pack()
b1 = Button(root, text='rock')
b1.pack()
b2 = Button(root, text='paper')
b2.pack()
b3 = Button(root, text='scissors')
b3.pack()
def btn1_click(event):
if askyesno("확인","Are you sure?"):
print("you played rock.")
np=random.randint(0,2)
up=0
print("Computer vs user :", end=" ")
if np == 0:
print("rock vs", end=" ")
elif np == 1:
print("paper vs", end=" ")
elif np == 2:
print("scissors vs", end=" ")
print("rock >>", end=" ")
if np==up:
print("Tie")
elif np==1:
print("Computer win")
else:
print("User win")
else:
pass
def btn2_click(event):
if askyesno("확인","Are you sure?"):
print("you played paper.")
np=random.randint(0,2)
up=1
print("Computer vs user :", end=" ")
if np == 0:
print("rock vs", end=" ")
elif np == 1:
print("paper vs", end=" ")
elif np == 2:
print("scissors vs", end=" ")
print("paper >>", end=" ")
if np==up:
print("Tie")
elif np==2:
print("Computer win")
else:
print("User win")
else:
pass
def btn3_click(event):
if askyesno("확인","Are you sure?"):
print("you played scissors.")
np=random.randint(0,2)
up=2
print("Computer vs user :", end=" ")
if np == 0:
print("rock vs", end=" ")
elif np == 1:
print("paper vs", end=" ")
elif np == 2:
print("scissors vs", end=" ")
print("scissors >>", end=" ")
if np==up:
print("Tie")
elif np==0:
print("Computer win")
else:
print("User win")
else:
pass
b1.bind('<Button-1>', btn1_click)
b2.bind('<Button-1>', btn2_click)
b3.bind('<Button-1>', btn3_click)
root.mainloop()
# listbox = Listbox(root, exportselection=False)
# label = Label(root, text='제목')
# entry = Entry(root)
# text = Text(root)
# b1 = Button(root, text='생성')
# b2 = Button(root, text='수정')
# b3 = Button(root, text='삭제')
# listbox.grid(row=0, column=0, columnspan=3, sticky='ew')
# label.grid(row=1, column=0)
# entry.grid(row=1, column=1, columnspan=2, sticky='ew')
# text.grid(row=2, column=0, columnspan=3)
# b1.grid(row=3, column=0, sticky='ew')
# b2.grid(row=3, column=1, sticky='ew')
# b3.grid(row=3, column=2, sticky='ew')
# root.mainloop()