【发布时间】:2019-06-07 22:36:43
【问题描述】:
所以我尝试将变量放入标签 x... 以便当变量更改时标签开始移动。
但问题是变量并没有改变它的值,而是当我按下“下一步”按钮时保持在“0”
需要帮助:
import tkinter as tk
from docx import Document
HEIGHT = 500
WIDTH = 600
root = tk.Tk()
canvas = tk.Canvas(root, height=HEIGHT, width=WIDTH)
canvas.pack()
nextt=tk.IntVar()
nextt=0 #setup the nextt variable
label1 = tk.Label(text='example:')
label1.place(x=90+nextt,y=50) #put the variable here to affect position
def next2():
nextt=300
button2 = tk.Button(text="Next", font=40, command=next2)
button2.place(x=230, y=440)
#when pressing this button,variable nextt should change to 300, but it doesnt
root.mainloop()
我已经尝试过使用 nextt.set=300 和/或 nextt.get(),所有可能的组合...
【问题讨论】:
-
您的
next2函数除了分配给局部变量之外什么都不做。 -
在
next2()函数内部,nextt变量是本地变量。它与同名的外部变量没有任何联系。 -
Ok..如何将它与x值中的变量连接起来?