じゃんけんゲームを作っているのですが、じゃんけんの結果はいつも「1~3の数字を入力してください。」になってしまいます。どうしたらいいでしょうか。
import
1from tkinter import font 2 3import random 4 5def btn_click(): 6 7 you=random.randint(1, 3) 8 9 me=textBox1.get() 10 11 def return_view(): 12 baseGround_new_csv.destroy() 13 14 baseGround_new_csv = tk.Tk() 15 # GUIの画面サイズ 16 baseGround_new_csv.geometry('300x200') 17 #GUIの画面タイトル 18 baseGround_new_csv.title('結果') 19 20 if me == you: 21 lbl_filename = tk.Label(baseGround_new_csv, text='あいこです。') 22 elif me == 1 and you == 2: 23 lbl_filename = tk.Label(baseGround_new_csv, text='相手はチョキを出しました。あなたの勝ちです') 24 elif me == 1 and you == 3: 25 lbl_filename = tk.Label(baseGround_new_csv, text='相手はパーを出しました。あなたの負けです') 26 elif me == 2 and you == 1: 27 lbl_filename = tk.Label(baseGround_new_csv, text='相手はグーを出しました。あなたの負けです。') 28 elif me == 2 and you == 3: 29 lbl_filename = tk.Label(baseGround_new_csv, text='相手はパーを出しました。あなたの勝ちです。') 30 elif me == 3 and you == 1: 31 lbl_filename = tk.Label(baseGround_new_csv, text='相手はグーを出しました。あなたの勝ちです。') 32 elif me == 3 and you == 2: 33 lbl_filename = tk.Label(baseGround_new_csv, text='相手はチョキを出しました。あなたの負けです。') 34 else: 35 lbl_filename = tk.Label(baseGround_new_csv, text='1~3の数字を入力してください。') 36 37 38 39 lbl_filename.pack() 40 41 # ボタン 42 btn_return = tk.Button(baseGround_new_csv, text='前のGUIの画面に戻る', command=return_view) 43 btn_return.pack() 44 baseGround_new_csv.mainloop() 45 46 47root=tk.Tk() 48root.title("じゃんけん") 49canvas=tk.Canvas(root,width=1400,height=900) 50canvas.pack() 51 52 53font1 = font.Font(family='Times', size=40) 54label1 = tk.Label(root, text="グーなら1", font=font1) 55label1.place(x=100,y=350) 56 57label2 = tk.Label(root, text="チョキなら2", font=font1) 58label2.place(x=550,y=350) 59 60label3 = tk.Label(root, text="パーなら3", font=font1) 61label3.place(x=1000,y=350) 62 63label4 = tk.Label(root, text="あなたが出す手は?", font=font1) 64label4.place(x=480,y=50) 65 66textBox1 = tk.Entry(width=60) 67textBox1.place(x=520, y=180) 68 69button=tk.Button(root,text="じゃーんけーん…",font=("Times New Roman",36),command=btn_click,fg="skyblue") 70button.place(x=500,y=240) 71 72me=textBox1.get() 73 74root.mainloop()
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/01/26 12:06
2022/01/26 12:19
2022/01/26 12:27