基本上我今天是学习Python的,我正在尝试制作我的第一个项目,这将是一个hang子手游戏,没什么特别的,只是要开始制作的东西。关于我的问题..如果按下某个键,如何弹出消息?我知道它是print(“ Message”)。但是,如何“检测”是否按下了某个键?这是代码(如我所说,该代码不是高级的。我今天开始学习):
from tkinter import *
root = Tk()
topFrame = Frame(root)
topFrame.pack()
bottomFrame = Frame(root)
bottomFrame.pack(side=BOTTOM)
A = Button(topFrame, text="A", bg="green", fg="white")
B = Button(topFrame, text="B", bg="green", fg="white")
C = Button(topFrame, text="C", bg="green", fg="white")
D = Button(topFrame, text="D", bg="green", fg="white")
E = Button(topFrame, text="E", bg="green", fg="white")
F = Button(topFrame, text="F", bg="green", fg="white")
G = Button(topFrame, text="G", bg="green", fg="white")
H = Button(topFrame, text="H", bg="green", fg="white")
I = Button(topFrame, text="I", bg="green", fg="white")
J = Button(topFrame, text="J", bg="green", fg="white")
K = Button(topFrame, text="K", bg="green", fg="white")
L = Button(topFrame, text="L", bg="green", fg="white")
M = Button(topFrame, text="M", bg="green", fg="white")
N = Button(topFrame, text="N", bg="green", fg="white")
O = Button(topFrame, text="O", bg="green", fg="white")
P = Button(topFrame, text="P", bg="green", fg="white")
Q = Button(topFrame, text="Q", bg="green", fg="white")
R = Button(topFrame, text="R", bg="green", fg="white")
S = Button(topFrame, text="S", bg="green", fg="white")
T = Button(topFrame, text="T", bg="green", fg="white")
U = Button(topFrame, text="U", bg="green", fg="white")
V = Button(topFrame, text="V", bg="green", fg="white")
W = Button(topFrame, text="W", bg="green", fg="white")
X = Button(topFrame, text="X", bg="green", fg="white")
Y = Button(topFrame, text="Y", bg="green", fg="white")
Z = Button(topFrame, text="Z", bg="green", fg="white")
A.pack(side=LEFT)
B.pack(side=LEFT)
C.pack(side=LEFT)
D.pack(side=LEFT)
E.pack(side=LEFT)
if A is pressed:
print("Wrong letter, that's a strike!")
root.mainloop()
我试过了
如果按A:print(“字母错误,这是警告!”)
它不起作用。
斯蒂芬大帝
肥皂起泡泡
相关分类