我需要使用计算函数将第二行添加到与第一行相同的位置。这段代码该怎么做
import tkinter as tk
root = tk.Tk()
root.geometry('850x450')
var1 = tk.StringVar()
t1 = tk.Entry(root, textvariable=var1).grid(row=1,column=1)
var2 = tk.StringVar()
t2 = tk.Entry(root, textvariable=var2).grid(row=1,column=2)
result = tk.StringVar()
l = tk.Label(root, textvariable=result).grid(row=1,column=3)
N = 3 # number of decimals that you want
def set_label(name, index, mode):
if var1.get() == '' or var2.get() == '':
pass
else:
res = float(var1.get()) * float(var2.get())
result.set('{number:.{digits}f}'.format(number=res, digits=N))
var1.trace('w', set_label)
var2.trace('w', set_label)
root.mainloop()
提前致谢...
墨色风雨
慕姐4208626
相关分类