0

I have created a file with different tables inside along with fields in each of the tables. When I use "db = sqlite3.connect('File')" it connects to the file but when I go to paste it in the text.grid, it doesn't appear to be organised. Is there a way to put it into a table so it looks more organised?

Here is some of the code I use, Thanks!!

def CustomerDetails():
    db = sqlite3.connect('File')
    cursor = db.cursor()
    sql1 = "select * FROM CustomerTable"
    cursor.execute(sql1)
    result = cursor.fetchall()
    count = (len(result))
    for each in result:
        out = each
        message = out
        text.insert(0.0, message)
        text.insert(0.0, '\n' )
    cursor.close()

and

# Frame 1 Heading buttons
labelspare=Label(f1, text =" ").grid(column=1, row=1, sticky=(W, E))
f1button1=Button(f1,  text="Current Orders").grid(column=2, row=2, sticky=(W,E), ipadx = 20, ipady = 10, padx = 5, pady = 5)
f1button2=Button(f1,  text="Order",command = CurrentOrders).grid(column=3, row=2, sticky=(W, E), ipadx = 20, ipady = 10, padx = 5, pady = 5)
f1button3=Button(f1,  text="Customer",command = CustomerDetails).grid(column=4, row=2, sticky=(W, E), ipadx = 20, ipady = 10, padx = 5, pady = 5)
f1button4=Button(f1,  text="Products",command = ProductDetails).grid(column=5, row=2, sticky=(W, E), ipadx = 20, ipady = 10, padx = 5, pady = 5)
labelspare=Label(f1, text =" ").grid(column=1, row=3, sticky=(W, E))
labelspare=Label(f1, text =" ").grid(column=1, row=4, sticky=(W, E))
text=Text(f1, width = 125, height = 42, wrap = WORD)
text.grid(row = 4,column=2,columnspan = 8, sticky =(W, E))

Basically, once the button is clicked the subroutine should run and paste the file into the text.grid but it just looks very unorganized, as though it literally just pasted the file in.

To resolve any confusion, I have added a picture of some fictitious data to show how "Unorganized" the data is. The fields don't align how I would like them too, similar to an excel spreadsheet. http://imgur.com/8MTPpAx

Coder101
  • 107
  • 2
  • 12
  • Possible duplicate of [Does tkinter have a table widget?](http://stackoverflow.com/questions/9348264/does-tkinter-have-a-table-widget) – Tadhg McDonald-Jensen Mar 09 '16 at 18:45
  • What does "looks more organized" mean. SQLite returns a list of tuples, so the selected data is organized as a list of tuples. If you want it in some other format, like sorted in some order for example, then it has to be converted from the basic Select. –  Mar 09 '16 at 19:21
  • FWIW, the proper first index in a text widget is the _string_ `"1.0"`, not the floating point number 0.0. – Bryan Oakley Mar 09 '16 at 19:23
  • 1
    For displaying multiple db rows, you might look as tkinter.ttk.Treeview. – Terry Jan Reedy Mar 10 '16 at 06:21
  • Thanks for your comments guys! In regards to Tadhg, It is similar but I want to know how I can not only create a table, but insert data from a file into it. I hope the picture has helped you Curly Joe, it may have been confusing just saying "unorganized" but hopefully the picture shows that the data sent when the button is clicked is just a little jumbled. I have explored the treeview and I'm not sure it does exactly what I want it to do. If any of you have used SQLBrowser, I want the data to be laid out as it would be with the use of that program. Thanks for all your support!! – Coder101 Mar 10 '16 at 21:25

0 Answers0