我对Pyton很新。 所以我试图制作一个显示多个用户输入的gui。我已经成功完成了两个输入(文本和数字):
类产品:
db_name = 'mydatabase.db'
def __init__(self, wind):
self.wind=wind
self.wind.title('Date pacienti')
frame = LabelFrame(self.wind, text='Add new record')
frame.grid(row=0, column=1)
Label(frame, text='Name:').grid(row=1, column=1)
self.name = Entry(frame)
self.name.grid(row=1, column =2)
Label(frame, text='Last name:').grid(row=2, column=1)
self.last = Entry(frame)
self.last.grid(row=2, column =2)
Label(frame, text = 'Age:').grid(row=3, column=1)
self.age=Entry(frame)
self.age.grid(row=3, column=2)
Label(frame, text = 'Something else:').grid(row=4, column=1)
self.else=Entry(frame)
self.else.grid(row=4, column=2)
ttk.Button(frame, text='Add record', command = self.adding).grid (row=5,column=2)
self.message=Label(text='', fg='red')
self.message.grid(row=3, column=0)
self.tree = ttk.Treeview (height=10, columns=2)
self.tree.grid(row=7, column=0, columnspan=2)
self.tree.heading('#0',text = 'Name', anchor=W)
self.tree.heading(2, text='Last name', anchor=W)
self.tree.heading(3, text = 'Age', anchor=W)
self.tree.heading(4, text='Something else', anchor=W)
self.viewing_records ()
def run_query(self, query, parameters =()):
with sqlite3.connect (self.db_name) as conn:
cursor = conn.cursor()
query_result = cursor.execute (query, parameters)
conn.commit()
return query_result
def viewing_records (self):
records = self.tree.get_children()
for element in records:
self.tree.delete (element)
query = 'SELECT * FROM pacienti ORDER BY nume DESC'
db_rows = self.run_query (query)
for row in db_rows:
self.tree.insert('', 0, text = row[1], value = row[3])
我想为用户添加更多文本字段以进行输入(例如text = row [2],row [4] ...)。 我该怎么做呢?