Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Tkinter按钮在使用列表时仅起作用一次_Python_Function_Tkinter_Tk - Fatal编程技术网

Python Tkinter按钮在使用列表时仅起作用一次

Python Tkinter按钮在使用列表时仅起作用一次,python,function,tkinter,tk,Python,Function,Tkinter,Tk,我试图用一个按钮在列表中循环。它只工作一次,但对任何其他压力都没有反应 cards = ["2 of Diamonds", "3 of Diamonds"] #etc (don't want it to be too long) current=0 def next(): 电流=+1 打印(“当前”变量值:,当前) config(text=cards[当前]) 下一步=按钮(文本=”⇛", command=next,fg=“白色”,bg=“红色”,activebackground=“#8b00

我试图用一个按钮在列表中循环。它只工作一次,但对任何其他压力都没有反应

cards = ["2 of Diamonds", "3 of Diamonds"] #etc (don't want it to be too long)
current=0
def next():
电流=+1
打印(“当前”变量值:,当前)
config(text=cards[当前])
下一步=按钮(文本=”⇛", command=next,fg=“白色”,bg=“红色”,activebackground=“#8b0000”,activeforeground=“白色”,relief=GROOVE)。网格(列=2,行=1)

有什么建议吗?

current
是一个局部变量,每次调用函数时,您都会将其初始化为
1

你需要做两件事:

  • 将当前<代码>声明为全局
  • 正确递增(
    +=
    而不是
    =+
例如:

def next():
    global current
    current += 1
    ...
通读