#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2017
    Posts
    29
    Rep Power
    0

    Arrow Separating columns of a listbox item and putting them into different entries


    please help...pleaaaaaase there is a 'gett' class(window)...there is a 'select trunck' button in it..when i select it, a new window will be opened('car' class)..in this new window,listbox created by sql tabel is shown I want to get a selected item from listbox created by a sql database and seprate id1, firs1 & las1 (columns of a sql table) and then put every one of these parts(id1, firs1,las1) into an entry in 'gett' class (it means that we need 3 entries in the parent window('gett' class)). i just could get whole of the listbox row.but i don't know how i seprate these parts???? what should I do?

    i created the listbox in 'readfromdatabase1' function and got the index of selected item from listbox in 'get_list' function.

    gett class
    Code:
    [class gett():########################################### for pushing 'empty' button
    
        def __init__(self,master):
    
    
            global enter1
    
    
            self.master=master
    ##        self.master.geometry('250x200+100+200')
            self.master.geometry('300x200')
            self.master.title('gett')
    
            self.button32 = Button(self.master,text="select trunck", command=self.jtruncmanag);  ### when i push it, it opens listbox related to 'trunmanag' table
            self.button32.grid(row=0, column=0)
    
    
            enter1 = Entry(self.master, bg='yellow')
            enter1.grid(row=4, column=4) 
    
    
        def jtruncmanag (self):         ### after pushing 'select trunck' button
            root10=Toplevel(self.master)
            mygui10=shojtrunmanag(root10)]
    car class
    Code:
     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)         ### for creating the table
            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)             ### for entering  "driver name"
            self.d.grid(row=1, column=1)
    
            self.e = Entry(self.master)             ### for entering "trunck type" 
            self.e.grid(row=2, column=1)
    
            self.f = Entry(self.master)             ### for entering "pelack"         
            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.readfromdatabase1()
    
    
        def tabluh1(self):
    
            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() 
    
        def readfromdatabase1(self):            ############## creating a listbox & inserting entries into it 
            self.cur.execute("SELECT * FROM trunmanage")
    
            rows = self.cur.fetchall()
            for row in rows:
    
                self.lb1 = Listbox(self.master)
                self.lb1.grid(row=5)
    
    
            for item in rows:
    
                self.lb1.insert(END, item)
    
        def get_list(self):                     ################ which item of listbox has been selected
    
            """
            function to read the listbox selection
            and put the result in an entry widget
            """
            global enter1                       ############### enter1 is a entry in another class(the parent window)
                                                ############### but i need 3 entries for seprating columns of a row of listbox(because i have 3 columns)
                                                ############### these entries are in the parent window()
    
    
            # get selected line index
            index = self.lb1.curselection()[0]
    
            # get the line's text
            seltext = self.lb1.get(index)
    
            #closing window
            self.master.destroy()
    
            # delete previous text in enter1
            enter1.delete(0, 50)
           # now display the selected text
            enter1.insert(0, seltext)
  2. #2
  3. Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Posts
    5,824
    Rep Power
    509
    I can't tell what you need. Here's your car class with the sql statement replaced by a list of lists. It runs on python3 without modification (if I post correct snip). Perhaps you could draw what you expect?
    Code:
    #! /usr/bin/python3
    
    from tkinter import *
    
    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)         ### for creating the table
            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)             ### for entering  "driver name"
            self.d.grid(row=1, column=1)
    
            self.e = Entry(self.master)             ### for entering "trunck type"
            self.e.grid(row=2, column=1)
    
            self.f = Entry(self.master)             ### for entering "pelack"
            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.readfromdatabase1()
    
    
        def tabluh1(self):
    
            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()
    
        def readfromdatabase1(self):            ############## creating a listbox & inserting entries into it
            #self.cur.execute("SELECT * FROM trunmanage")
    
            #rows = self.cur.fetchall()
    
            rows = [['({},{})'.format(r,c) for c in 'abcdefgh'] for r in range(20)]
    
            for row in rows:
    
                self.lb1 = Listbox(self.master)
                self.lb1.grid(row=5)
    
    
            for item in rows:
    
                self.lb1.insert(END, item)
    
        def get_list(self):                     ################ which item of listbox has been selected
    
            """
            function to read the listbox selection
            and put the result in an entry widget
            """
            global enter1                       ############### enter1 is a entry in another class(the parent window)
                                                ############### but i need 3 entries for seprating columns of a row of listbox(because i have 3 columns)
                                                ############### these entries are in the parent window()
    
    
            # get selected line index
            index = self.lb1.curselection()[0]
    
            # get the line's text
            seltext = self.lb1.get(index)
    
            #closing window
            self.master.destroy()
    
            # delete previous text in enter1
            enter1.delete(0, 50)
            # now display the selected text
            enter1.insert(0, seltext)
    
    master = Tk()
    a = car(master)
    master.mainloop()
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2017
    Posts
    29
    Rep Power
    0

    separating different parts of a listbox


    this is not my problem
    in generally, how can i seprate the different psrts of one item from listbox.
    in reality, this item is a row of the listbox. the different parts of a item (a row)is seprated by columns...
    please one clue
  6. #4
  7. Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Posts
    5,824
    Rep Power
    509
    Provide a sample input and a picture showing how you'd like to see it.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo