Show_msg(msg_display,'normal')# success message Msg_display="Number of records updated: " + str(id.rowcount) Show_msg(msg_display,'error') # send error message Price=%s,p_cat=%s, available=%s WHERE p_id=%s",data) Id=my_conn.execute("UPDATE plus2_products SET p_name=%s,unit=%s,\ This function will receive the value of product id (p_id) and reads all the input data as edited by the user.Īs the user enters or updates the data, we will be using try except error handling to manage the data updating.Īfter updating the record, we will reset all the input fields and refresh the Treeview ( trv ) to reflect the new data by calling the show_items() function.ĭef my_update(p_id): # receives the p_id on button click to updateĭata=(p_name.get(),unit.get(),price.get(),p_cat.get(),available.get(),p_id ) Note the last line inside the if block where we are passing the p_id value ( selected ) to the function my_update(p_id), based on the selection of rows this value will change. Selected=trv.focus() # gets the product id or p_idĮ_p_cat.set(my_cats]) # set the category valueī_nfig(command=lambda:my_update(selected)) Using the elements of s we will assign value to our variables to display inside edit widgets.ĭef data_collect(self): # collect data to display for edit S = row.fetchone() # row details as tuple Query="SELECT * from plus2_products WHERE p_id=%s" The value of the selected node is our p_id ( product id ), using this p_id as parameter in WHERE condition we will collect the data from MySQL product table. Inside this function data_collect() first we read the iid ( p_id ) of the selected node. On selection of any node or row of the treeview, this function is triggered. Values=(dt,dt,dt,dt,dt)) data_collect(self) : Collect and show data R_set=my_conn.execute(query,cat) # get the record set from table Query="SELECT * FROM plus2_products WHERE p_cat=%s" This function is called on every update of rows of data to reflect the changes.ĭef show_items(cat): # Populating the treeview with recordsįor item in trv.get_children(): # loop all child items Before displaying ( inserting ) the data inside treeview all previous child nodes ( rows of data ) is removed. This function will receive the category value as integer ( 1, 2 or 3 for Breakfast, Lunch and dinner ) and collect the data from plus2_products table. On selection of row of Treeview, populate the Entry widgets for Edit.ĭisplay Message to user with time delay ( details of show_msg() )Ĭonnection to MySQL and creating tables Read the connection details and download the SQL dump to create tables from Restaurant-V-3 show_item(cat) : Display the records in Treeview Once updated ( in MySQL table ) fresh data will be taken from the product table showing the changes.Ĭollects data from MySQL table and populate the Treeview. User can select any row and details of the record will be displayed for edit and update. Select the row to Edit and update records from MySQL table using Tkinter Treeviewīased on the input category, the records will be collected from MySQL product table( plus2_products ) and shown inside a Treeview.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |