Python Forum
printing selected item with Sqlite data
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
printing selected item with Sqlite data
#1
Hi All,

It has been some time since I have finished writing my program. I have run into a problem where I am trying to print and export data from sqlite3 db to a form so I can modify/edit the data and then update it.

Currently when I am printing the selected Treeview item back to console, this is what I get:

['', '', [9006, u'SW07', u'Cisco 2950-48', u'CAT586868293', 40], 0, '']
values are (left to right):
product ID
device name
device model
device serial
pallet number

I would then like to create a form which populates entry fields in order for me to modify and rewrite those changes to the sqlite db. (unfortunately I deleted this bit of code as I kept getting lots of errors)

Also, what are the u'?


Sorry for sounding Huh, but I currently am new to python and learning it as I go.

Below is the line of code.

def funcEditInvent():
	selected_item=tree1.selection()
	device=tree1.item(selected_item)
	device=list(device.values())
	print (device)
Reply
#2
what type of form?
example curses, tkinter, Qt, wxpython, kivy
you might just want to use one of the available tools
DbBrowser: https://sqlitebrowser.org/
sqlite studio: https://sqlitestudio.pl/index.rvt
http://sqliteadmin.orbmu2k.de/
there are more
Reply
#3
Hi Larz60+

Thanks for your message. I have pm'd you but thought I would reply here also for others to possibly help out.

I have uploaded 3 images: (3rd link is my intention)
https://ibb.co/L0R5mrQ
https://ibb.co/ccsFTNr
https://ibb.co/6Jfb5DS

Simply put, I would like to extract data from an SQLite db into a tkinter text entry form in order for me to modify/edit and then submit (UPDATE query) the changes back to the db.
I am having trouble getting this to work. Below is the error that I am getting when I click the "edit" button.

└──╼ #python index-testing.py
['', '', [9004, u'SW05', u'Cisco 2950-48', u'CAT888484111', 30], 0, '']
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1550, in __call__
return self.func(*args)
File "index-testing.py", line 947, in funcEditInvent
EditInvent()
File "index-testing.py", line 950, in EditInvent
TopEditInvent = Frame(EditInvent, width=600, height=100, bd=1, relief=SOLID)
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 2583, in __init__
Widget.__init__(self, master, 'frame', cnf, {}, extra)
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 2095, in __init__
BaseWidget._setup(self, master, cnf)
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 2073, in _setup
self.tk = master.tk
AttributeError: 'function' object has no attribute 'tk'
Reply
#4
Please don't use private mail.
Post here so that all can benefit.
Reply
#5
Yep Sorry Larz60+, I realised that after and hence posted it here also.
Reply
#6
here is what my line of code when I click the Edit button.
I know that I will need to insert the SQL data into the text box. For the time being I am even having trouble getting the window to display the labels and fields.. not sure what I am missing?

Error
python index-testing.py
['', '', [9001, u'SW02', u'Cisco 2950-48', u'CAT746574576', 10], 0, '']
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1550, in __call__
return self.func(*args)
File "index-testing.py", line 935, in funcEditInvent
EditInvent()
File "index-testing.py", line 948, in EditInvent
EditForm()
File "index-testing.py", line 951, in EditForm
TopEditForm = Frame(EditForm, width=600, height=100, bd=1, relief=SOLID)
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 2583, in __init__
Widget.__init__(self, master, 'frame', cnf, {}, extra)
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 2095, in __init__
BaseWidget._setup(self, master, cnf)
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 2073, in _setup
self.tk = master.tk
AttributeError: 'function' object has no attribute 'tk'



Code below

def funcEditInvent():
	selected_item=tree1.selection()
	device=tree1.item(selected_item)
	device=list(device.values())
	print (device)
	EditInvent()
	
def EditInvent():
    editform = Toplevel()
    editform.title("ACT/Edit Inventory")
    width = 600
    height = 500
    screen_width = Home.winfo_screenwidth()
    screen_height = Home.winfo_screenheight()
    x = (screen_width/2) - (width/2)
    y = (screen_height/2) - (height/2)
    editform.geometry("%dx%d+%d+%d" % (width, height, x, y))
    editform.resizable(0, 0)
    EditForm()
    
def EditForm():
    TopEditForm = Frame(EditForm, width=600, height=100, bd=1, relief=SOLID)
    TopEditForm.pack(side=TOP, pady=20)
    lbledit_text = Label(EditForm, text="Add New Device", font=('monospace', 16), width=600)
    lbledit_text.pack(fill=X)
    MidEdit = Frame(EditForm, width=600)
    MidEdit.pack(side=TOP, pady=50)
    lbl_changename = Label(MidEdit, text="Device Name:", font=('monospace', 15), bd=10)
    lbl_changename.grid(row=0, sticky=W)
    lbl_changemodel = Label(MidEdit, text="Device Model:", font=('monospace', 15), bd=10)
    lbl_changemodel.grid(row=1, sticky=W)
    lbl_changeserial = Label(MidEdit, text="Device Serial", font=('monospace', 15), bd=10)
    lbl_changeserial.grid(row=2, sticky=W)
    lbl_changelocation = Label(MidEdit, text="Pallet Number:", font=('monospace', 15), bd=10)
    lbl_changelocation.grid(row=3, sticky=W)
    devicename_new = Entry(MidEdit, textvariable=device_name, font=('monospace', 15), width=15)
    devicename_new.grid(row=0, column=1)
    devicemodel_new = Entry(MidEdit, textvariable=device_model, font=('monospace', 15), width=15)
    devicemodel_new.grid(row=1, column=1)
    deviceserial_new = Entry(MidEdit, textvariable=device_serial, font=('monospace', 15), width=15)
    deviceserial_new.grid(row=2, column=1)
    devicelocation_new = Entry(MidEdit, textvariable=pallet_number, font=('monospace', 15), width=15)
    devicelocation_new.grid(row=3, column=1)
    btn_submitchanges = Button(MidEdit, text="Save Changes", font=('monospace', 16), width=10, bg="#009ACD")
    btn_submitchanges.grid(row=4, columnspan=2, pady=20)
Reply
#7
some strategically placed empty lines would make your code much more readable.
I don't see any bind, or command that would direct button events
either within the Button instantiation on line 44, you need a command statement with event function name,
or a bind statement immediately after the Button instantiation
Reply
#8
Yeah, sorry it is only a snippet of my code as it's approximately 1000+ lines.

The button function on save changes I've removed temporarily. Only kept the minimum to figure out the reason the form isn't being displayed. Would you like me to post the entire code (I'd rather send it to you in a DM)
Reply
#9
Hi Guys, Larz60+

Ok, this is what I can get so far. image URL: https://ibb.co/MpNdfTk

What I need is to split the data queried from SQLite > I guess it needs to be set as a tuple and return the fields into the appropriate text entry fields.

Can someone help me with this?
Reply
#10
Ok, I figured the only way I could possibly get help is if i provide the code. URL is a zip file of the db, py and image.
http://www.filedropper.com/whacky7devbuild01adctool

The edit/update functions are on lines 924 to 985. (the sqlite update function is not present as of yet. just the entry/update form)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  need help with data analysing with python and sqlite Hardcool 2 299 Jan-30-2024, 06:49 AM
Last Post: Athi
  Remove an item from a list contained in another item in python CompleteNewb 19 5,544 Nov-11-2021, 06:43 AM
Last Post: Gribouillis
  Extracting and printing data ajitnayak1987 0 1,387 Jul-28-2021, 09:30 AM
Last Post: ajitnayak1987
  Error while transferring data from sqlite to elasticsearch - please help! ps96068 1 2,629 Jun-12-2021, 09:24 AM
Last Post: ibreeden
  Importing data from a text file into an SQLite database with Python macieju1974 7 4,011 Jun-29-2020, 08:51 PM
Last Post: buran
  Printing data scratchmyhead 4 2,648 Nov-08-2019, 11:25 PM
Last Post: jefsummers
  How can I only receive data from selected serial numbers MasterCATZ 7 3,465 Apr-20-2019, 08:35 AM
Last Post: MasterCATZ
  Need help with SQLite data input donmerch 4 5,702 Feb-06-2018, 10:09 AM
Last Post: donmerch

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020