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