单独从列中获取值并通过标签显示 - Python

时间:2018-05-03 13:37:41

标签: 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=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)

当我运行此代码时,我收到一条错误消息:

  

仅限TUPLE(非str)到元组

1 个答案:

答案 0 :(得分:0)

您可以使用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)