如何从数据库的每一列中分别获取值,并在python中通过标签显示每个值?
类显示:
def __init__(self, master,ad):
self.master = master
self.master.title("STUDENT-INFO")
self.f = Frame(self.master,height = 1200, width = 1200)
self.f.propagate(0)
self.f.pack()
self.e1=ad.e1.get()
self.e2=ad.e2.get()
self.b1=Button(self.master,text="PRINT",width=15,command=self.print1)
self.b1.place(x=35,y=200)
self.exit = Button(self.f, text = 'EXIT', width = 15, command = self.exit_window)
self.exit.place(x=35,y=400)
def print1(self):
cursor.execute("select emp_name,pf,monthly_sal_inhand,bonus,yearly_sal_inhand from details6 where emp_id='{}' and password='{}'".format(self.e1,self.e2))
r=cursor.fetchall()
s=r[0]+""+r[1]+""+r[2]+""+r[3]
self.l3=Label(self.master,text='Format : Employee_name Monthly_pf Final_monthly_salary Yearly_Bonus Final_yearly_salary ',width=120)
self.l3.place(x=250,y=200)
self.l3=Label(self.master,text=s,width=80)
当我运行这段代码时,我会收到一条错误消息:
只连接元组(不是str)到元组
发布于 2018-07-31 06:38:19
通过使用listWidget,您可以更好地将它们垂直打印在列表中。
def print1(self):
list1 = []
cursor.execute("select emp_name,pf,monthly_sal_inhand,bonus,yearly_sal_inhand from
details6 where emp_id='{}' and password='{}'".format(self.e1,self.e2))
r=cursor.fetchall()
for i in range(len(r)):
list1.append(r[i][0])
#Now we have all the elements in list1 as a list
for in range(len(list1)):
item=list1[i]
self.listWidget.addItem(item)
https://stackoverflow.com/questions/50156461
复制