我有一个项目,每当您按向上箭头时,我都希望更改全局变量size
。这是我的代码的一部分:
size = 10
def increase():
global size
size += 1
print("hi")
screen.onkeypress(increase, "Up")
但是当我运行该程序并按向上箭头,然后选中size
时,它仍然是10。
知道为什么吗?
感谢您的帮助。 = D
答案 0 :(得分:0)
您必须包括 listen()方法来记录您的操作。
size = 10
def increase():
global size
size += 1
print("hi")
screen.onkey(increase, "Up")
screen.listen()