import tkinter as tk import random def hand(rpc): if(rpc==0): return "Rock" if(rpc==1): return "Paper" if(rpc==2): return "Scissors" def checkwinner(chand,yhand): if yhand==chand: print("Draw!") result=tk.Label(window,text="Draw!",width=10) else: if(yhand==0) and (chand==2): print("You win!") result=tk.Label(window,text="You win!",width=10) else: if(yhand==0) and (chand==1): print("You lose!") result=tk.Label(window,text="You lose!",width=10) if(yhand==1) and (chand==0): print("You win!") result=tk.Label(window,text="You win!",width=10) else: if(yhand==1) and (chand==2): print("You lose!") result=tk.Label(window,text="You lose!",width=10) if(yhand==2) and (chand==1): print("You win!") result=tk.Label(window,text="You win!",width=10) else: if(yhand==2) and (chand==0): print("You lose!") result=tk.Label(window,text="You lose!",width=10) return result import random comphand=random.randint(0,2) def rock(): comphand=random.randint(0,2) result=tk.Label(window,text="You win!",width=10) result=tk.Label(window,text="Draw!",width=10) result=tk.Label(window,text="You lose!",width=10) checkwinner(comphand,0) def paper(): comphand=random.randint(0,2) result=tk.Label(window,text="You win!",width=10) result=tk.Label(window,text="Draw!",width=10) result=tk.Label(window,text="You lose!",width=10) checkwinner(comphand,1) def scissors(): comphand=random.randint(0,2) result=tk.Label(window,text="You win!",width=10) result=tk.Label(window,text="Draw!",width=10) result=tk.Label(window,text="You lose!",width=10) checkwinner(comphand,2) import tkinter as tk window=tk.Tk() window.geometry("640x300") window.title("Rock-Paper-Scissors Game") window.configure(bg="#FFFFFF") canvas=tk.Canvas(window,bg="#FFFFFF",width=640,height=220) canvas.place(x=0,y=0) rockImage=tk.PhotoImage(file="rock.gif") paperImage=tk.PhotoImage(file="paper.gif") scissorsImage=tk.PhotoImage(file="scissors.gif") canvas.create_image(10,30,image=rockImage,anchor="nw") canvas.create_image(210,30,image=paperImage,anchor="nw") canvas.create_image(410,30,image=scissorsImage,anchor="nw") rockbutton=tk.Button(window,text="Rock",width=6,command=rock) paperbutton=tk.Button(window,text="Paper",width=6,command=paper) scissorsbutton=tk.Button(window,text="Scissors",width=6,command=scissors) rockbutton.place(x=80,y=230) paperbutton.place(x=280,y=230) scissorsbutton.place(x=480,y=230) result=tk.Label(window,text="You win!",width=10) result.place(x=270,y=270)
やりたいことが丸投げの質問はあまりよくありません。
何ができないのか、どのようなエラーなのか、記載してほしいです。
同じ質問ですか?
もうひとつの方に回答しました。 https://teratail.com/questions/v90o6sljcz06ee

回答1件
あなたの回答
tips
プレビュー