我在Tkinter窗口上有一个按钮,该按钮将我带到带有某些Checkbuttons的第二个Tkinter窗口。如果我单击它们,则分配的变量不会更改。第二个窗口本身就可以正常工作。
test2.py
from Tkinter import *
import test
window = Tk()
btn = Button(window, command=test.main)
btn.pack()
window.mainloop()
test.py
from Tkinter import *
from functools import partial
def func(n):
print var[n].get()
def main():
window = Tk()
global var
var = [IntVar(), IntVar()]
i = 0
ck = Checkbutton(window, variable=var[i], command=partial(func,i))
ck.grid(row = 0, column = 0)
i += 1
ck2 = Checkbutton(window, variable=var[i], command=partial(func,i))
ck2.grid(row = 1, column = 0)
window.mainloop()
# main()