获取值';分别从列中删除,并通过Label-Python显示

获取值';分别从列中删除,并通过Label-Python显示,python,Python,如何分别从数据库的每一列中获取值,并在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=a

如何分别从数据库的每一列中获取值,并在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)连接到元组

您可以使用listWidget以更好的方式在列表中垂直打印它们。
请发布完整的错误消息好吗?
fetchall
返回一个行序列,每一行都是字段序列(这里是元组)。我认为您需要的是
r=cursor.fetchone()
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)