代码如下所示,但未重新定位条目小部件位置,也未创建标签。在输入此代码之前 [ e1.grid(row=1,column=1) ] 程序工作正常,输入代码后不工作,如何处理这个问题..
该程序是
try :
import tkinter as tk # Python 3
except :
import Tkinter as tk # Python 2
def update_sum() :
# Sets the sum of values of e1 and e2 as val of e3
try :
sum_tk.set((float(e1_tk.get().replace(' ', '')) + float(e2_tk.get().replace(' ', ''))))
except :
pass
root.after(10, update_sum) # reschedule the event
return
root = tk.Tk()
root.geometry('850x450')
e1_tk = tk.StringVar(root) # Initializes a text variable of tk to use to get e1's val.
e2_tk = tk.StringVar(root) # Initializes a text variable of tk to use to get e2's val.
sum_tk = tk.StringVar(root) # Initializes a text variable of tk to use to set e3's val.
# Entries
e1 = tk.Entry(root, textvariable = e1_tk)
e1.grid(row=1,column=1)
e2 = tk.Entry(root, textvariable = e2_tk)
e2.grid(row=1,column=2)
e3 = tk.Entry(root, textvariable = sum_tk)
e3.grid(row=1,column=3)
e1=Label(root,text="SL")
e1.grid(row=1,column=0)
e1.pack()
e2.pack()
e3.pack()
# Will update the sum every second 10 ms = 0.01 second it takes ms as arg.
root.after(10, update_sum)
root.mainloop()
提前致谢..
慕少森
相关分类