follownig代码包含条目小部件和列表框,我需要从entrywidgets将数据插入到列表框。但是在这段代码中,我不知道该怎么做。而且我不知道该怎么问。 我为我的英语不好对不起。
import tkinter as tk
from tkinter import ttk
root = tk.Tk()
root.geometry('850x450')
def add_row(row_number):
var1 = tk.StringVar()
t1 = tk.Entry(root, textvariable=var1).grid(row=row_number,column=1)
var2 = tk.StringVar()
t2 = tk.Entry(root, textvariable=var2).grid(row=row_number,column=2)
result = tk.StringVar()
l = tk.Label(root, textvariable=result).grid(row=row_number,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)
e1=tk.Label(root,text="mrp").grid(row=1,column=0)
e2=tk.Label(root,text="krl").grid(row=2,column=0)
e3=tk.Label(root,text="ipl").grid(row=3,column=0)
e4=tk.Label(root,text="vpl").grid(row=4,column=0)
NUMBER_OF_ROWS = 4
for row_number in range(1, NUMBER_OF_ROWS+1):
add_row(row_number)
cols = ('Item', 'PRICE', 'QTY', 'Total')
listBox = ttk.Treeview(root, columns=cols, show='headings')
for col in cols:
listBox.heading(col, text=col)
listBox.grid(row=1, column=0, columnspan=2)
listBox.place(x=10, y=200)
root.mainloop()
先谢谢了。