printing selected item with Sqlite data - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: printing selected item with Sqlite data (/thread-23762.html) Pages:
1
2
|
printing selected item with Sqlite data - whacky7 - Jan-16-2020 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 , 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) RE: printing selected item with Sqlite data - Larz60+ - Jan-16-2020 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 RE: printing selected item with Sqlite data - whacky7 - Jan-17-2020 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' RE: printing selected item with Sqlite data - Larz60+ - Jan-17-2020 Please don't use private mail. Post here so that all can benefit. RE: printing selected item with Sqlite data - whacky7 - Jan-17-2020 Yep Sorry Larz60+, I realised that after and hence posted it here also. RE: printing selected item with Sqlite data - whacky7 - Jan-19-2020 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) RE: printing selected item with Sqlite data - Larz60+ - Jan-19-2020 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 RE: printing selected item with Sqlite data - whacky7 - Jan-19-2020 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) RE: printing selected item with Sqlite data - whacky7 - Jan-20-2020 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? RE: printing selected item with Sqlite data - whacky7 - Jan-21-2020 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) |