import tkinter import time import msvcrt import keyboard questions1=[ {"question":"問1","answer":"B"}, {"question":"問2","answer":"A"}, {"question":"問3","answer":"B"}, {"question":"問4","answer":"A"}, {"question":"問5","answer":"B"}, ] pimg = tkinter.PhotoImage(file="img/Q1.png") trueimg = tkinter.PhotoImage(file="img/A1.png") falseimg = tkinter.PhotoImage(file="img/A2.png") root = tkinter.Tk() root.minsize(320, 240) canvas = tkinter.Canvas(root, width=320, height=240) canvas.place(x=0, y=0) canvas.create_image(320, 240, image=pimg) root.update() index=random.randint(5) ans=questions1[index]['answer'] while True: try: if keyboard.is_pressed('a'): print('You Pressed a Key!') # 動作確認のため keyP="A" break elif keyboard.is_pressed('b'): print('You Pressed b Key!') # 動作確認のため keyP="B" break else: pass except: break print(keyP) # 動作確認のため if keyP==ans : canvas.place(x=0, y=0) canvas.create_image(320, 220, image=trueimg,tag="illust") root.update() time.sleep(1) else: canvas.place(x=0, y=0) canvas.create_image(320, 220, image=falseimg,tag="illust") root.update() time.sleep(1) root.mainloop()
現状うまくいかないコードを追記お願いします。
回答2件
あなたの回答
tips
プレビュー