0
我希望文本出现并在每个窗口中更新,而不是仅在一个窗口中更新。我注意到工作的窗口始终是第一个被调用的窗口,但这并不能帮助我解决问题。Python 2.7 Tkinter - 多窗口条目更新
我注意到的另一件事是,程序接受将新值输入到首先显示值的窗口中,但是任何通过在第二个窗口中输入值来更改de
值的尝试都失败。
这里是我的代码的简化版本:
from Tkinter import *
root = Tk()
root2 = Tk()
de= IntVar()
de.set(0)
def previous():
de.set(de.get()-1)
def Next():
de.set(de.get()+1)
def go_to(event) :
de.set(de.get())
button4 =Button(root2, text='Next', command=Next)
button4.grid(row=26 ,column=9, columnspan=2, rowspan=1,padx=0, pady=0, sticky=W+E+N+S)
button5 =Button(root2, text='Previous', command=previous)
button5.grid(row=26, column=6, columnspan=2, rowspan=1,padx=0, pady=0, sticky=W+E+N+S)
label1=Label(root2, text = 'Go to2')
entry1 = Entry(root2,textvariable=de,bd=1,width=3)
entry1.bind("<Return>", go_to)
label1.grid(row=25, column=8, columnspan=1, rowspan=1,padx=0, pady=0)
entry1.grid(row=26, column=8, columnspan=1, rowspan=1,padx=0, pady=0)
button3 =Button(root, text='Next', command=Next)
button3.grid(row=26 ,column=9, columnspan=2, rowspan=1,padx=0, pady=0, sticky=W+E+N+S)
button2 =Button(root, text='Previous', command=previous)
button2.grid(row=26, column=6, columnspan=2, rowspan=1,padx=0, pady=0, sticky=W+E+N+S)
label=Label(root, text = 'Go to1')
entry = Entry(root,textvariable=de,bd=1,width=3)
entry.bind("<Return>", go_to)
label.grid(row=25, column=8, columnspan=1, rowspan=1,padx=0, pady=0)
entry.grid(row=26, column=8, columnspan=1, rowspan=1,padx=0, pady=0)
root2.mainloop()
root.mainloop()
太棒了,你从很多麻烦中救了我,实际上改善了我的理解,谢谢。 – 2014-12-03 23:08:27