Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 seprating columns of an listbox item and putting them into different entry
#1
i want to get a selected item from listbox created bu a sql database and seprate 'id1', 'firs1' & 'las1' (columns of a sql table) and then put every one these parts(id1, firs1,las1) into a aside entry(it means that we need 3 entries) what shoud i do?...please help..this is a part of my code

creating listbox is in 'car' class and entries are in 'gett' class

class car():####################################################  trunck manage
     
    def __init__(self,master):

        ##super(car,self).__init__()
##        tk.Frame.__init__(self, master)
        
        self.master=master
        ##self.master.geometry('500x600+100+200')
        self.master.geometry('600x500')
        self.master.title('Report')
        self.button28 = Button(self.master,text="create", command=self.tabluh1)
        self.button28.grid(row=0, column=0)

        self.button29 = Button(self.master,text="insert rec", command=self.insertar1)
        self.button29.grid(row=3, column=2)

        self.tyLabel1 = Label(self.master,text="driver name")
        self.tyLabel1.grid(row=1, column=0)

        self.disLabel1 = Label(self.master,text="trunck type")
        self.disLabel1.grid(row=2, column=0)

        self.pelLabel1 = Label(self.master,text="pelack")
        self.pelLabel1.grid(row=3, column=0)


        self.d = Entry(self.master) 
        self.d.grid(row=1, column=1)

        self.e = Entry(self.master) 
        self.e.grid(row=2, column=1)

        self.f = Entry(self.master) 
        self.f.grid(row=3, column=1)

        self.connection = sqlite3.connect('jadval.db')
        self.cur = self.connection.cursor()
        self.dateLabel1 = Label(self.master, text="driver name", width=10)
        self.dateLabel1.grid(row=4, column=0)
        self.BMILabel1 = Label(self.master, text="trunck type", width=10)
        self.BMILabel1.grid(row=4, column=1)
        self.stateLabel1 = Label(self.master, text="pelack", width=10)
        self.stateLabel1.grid(row=4, column=2)

        self.button1 = Button(self.master, text='OK', command=self.get_list)
        self.button1.grid(row=6, column=3)


##        self.enter1 = Entry(self.master, bg='yellow')
##        self.enter1.grid(row=8, column=3)
        
        self.readfromdatabase1()
        ##self.showallrecords1()

##    def showallrecords1(self):
##        
##        data1 = self.readfromdatabase1()
##        for index1, dat1 in enumerate(data1):
##            Label(self.master, text=dat1[0]).grid(row=index1+5, column=0)
##            Label(self.master, text=dat1[1]).grid(row=index1+5, column=1)
##            Label(self.master, text=dat1[2]).grid(row=index1+5, column=2)
        
    def tabluh1(self):
        ##pragma encoding=utf8;
        c.execute('''CREATE TABLE trunmanage(id1 INTEGER,firs1 stringvar(10),las1 stringvar(10))''')
        ##c.execute('''CREATE TABLE trunmanage(id1 INTEGER,firs1 stringvar(10),las1 stringvar(10))''')
    def insertar1(self):

        d1=self.d.get()
        e1=self.e.get()
        f1=int(self.f.get())
        c.execute("INSERT INTO trunmanage (id1, firs1,las1 ) VALUES (?, ?, ?)",(f1, d1, e1))
        conn.commit()
        self.readfromdatabase1() 
        ##self.showallrecords1()

    def readfromdatabase1(self):
        self.cur.execute("SELECT * FROM trunmanage")
        ##return self.cur.fetchall()
        rows = self.cur.fetchall()
        for row in rows:

            ##lb1 = Listbox(self.master)
            self.lb1 = Listbox(self.master)

            ##lb1.grid(row=5)
            self.lb1.grid(row=5)

        for item in rows:

            ##lb1.insert(END, item)
            self.lb1.insert(END, item)

    def get_list(self):
        """
        function to read the listbox selection
        and put the result in an entry widget
        """
        global enter1
        
        # get selected line index
        
        ##index = lb1.curselection()[0]
        index = self.lb1.curselection()[0]
        
        # get the line's text
        
        ##seltext = lb1.get(index)
        seltext = self.lb1.get(index)

        self.master.destroy()
        
        # delete previous text in enter1
        enter1.delete(0, 50)
##        # now display the selected text
        enter1.insert(0, seltext)


Quote
#2
Please, use python code tags. Also, post minimal runnable snippet that reproduce your problem.
Quote
#3
ok---the first post was modified
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Python Tkinter treeview showing 6 columns instead of 11 columns wei321 1 801 Feb-27-2020, 04:01 AM
Last Post: Larz60+
  How to get the selected item from Listbox and convert it to int? Jionni 8 561 Feb-17-2020, 11:07 AM
Last Post: Jionni
  Transfer Toplevel window entry to root window entry with TKinter HBH 0 1,165 Jan-23-2020, 09:00 PM
Last Post: HBH
  [Tkinter] Need help please properly putting tabs within a PanedWindow JackMack118 2 478 Dec-08-2019, 03:02 PM
Last Post: balenaucigasa
  [Tkinter] how to get the entry information using Entry.get() ? SamyPyth 2 1,096 Mar-18-2019, 05:36 PM
Last Post: woooee
  [Tkinter] taking bad listbox items after lowering it to 1 item deadmarshal 3 1,046 Jul-18-2018, 04:16 PM
Last Post: woooee

Forum Jump:


Users browsing this thread: 1 Guest(s)