![]() R_set=my_conn. Once the connection object my_conn is created then the code remain same in case of SQLAlchemy. We used variable i as index for each row and variable j as each column of data. In this variable student is a tuple and it contains one row of data. ![]() We will use one tkinter entry component to display each data in the window. This will print 10 rows of records from student table. R_set=my_conn.execute('''SELECT * from student LIMIT 0,10''') ![]() So we used another for loop to display each element of this tuple. ![]() Each row of data ( here student ) is a tuple. We will use one for loop to collect each row of record from the data set. We used the returned record set i.e r_set as an iterator. My code creates a gui with input boxes, a button, and a treeview. This result set contains all our (10) records. Tkinter Not getting entry values on button click & treeview not updating First problem. Note that SQLite database executes the query part only and return us one result set. You can change this figure to get different number of records from the database. We will use Query with LIMIT to collect 10 records from the student table.īy using LIMIT Query we are restricting our number of records by getting 10 records only from SQLite database. We will use my_conn in our further script as the connection object to get our records.ĭownload or Create my_db.db SQLite Database » The commented line is used when we keep SQLite database in Google Drive. In windows system, the absolute path is used in above code. #my_conn=create_engine("sqlite:////content/drive/MyDrive/db/my_db.db") My_conn = nnect('my_db.db') using SQLAlchemy connection from sqlalchemy import create_engine We connected to sqlite database and create our student table with sample data. Tree=ttk.Displaying records from SQLite table « Basics of Python TkinterĬonnect & create table in sqlite database display rows from Student tableĭisplay records from sqlite Student table in Tkinter window. #-creates button with command to run adding_records() method on click-ī1 = tk.Button(framet, text='Add', command=lambda : adding_records(var1,var2,var3, var4, var5, var6)) #-sets entry data into variables to pass to method. Label6 = tk.Label(framet, text='Condition: ', width=15) Label5 = tk.Label(framet, text='Unit: ', width=15) Label4 = tk.Label(framet, text='Price: ', width=15) Label3 = tk.Label(framet, text='Manufacturer: ', width=15) (If I put the example URL in the URL entry box, I want the example ID in the ID box automatically generated and vice versa) If a user fills in the ID box, the URL is automatically generated. Label2 = tk.Label(framet, text='Description: ', width=15) If a user fills in the URL box, the ID is automatically generated. Label1 = tk.Label(framet, text='Material ID: ', width=15) Run_query(query, (matID, descr, manuf, price, unit, condition)) Query = "INSERT INTO parts VALUES (?, ?, ?, ?, ?, ?)" Tree.insert('', 0, text = row, values = (row, row, row, row, row, row))ĭef adding_records(matID, descr, manuf, price, unit, condition): Query_result = cursor.execute(query, parameters) I have tried placing it in the mainloop per some searching, but no success. I must close out the program and re-run it for it to show up. When a record is added via the button and method, it does not refresh in the treeview. When I click the button, it runs my adding_records method, but it adds blank records.įrom what I can gather, when the button is clicked, it runs the adding_records() method before the entries are able to be set into variables, thus the variables being passed to the method are empty.įrom what I searched, the lambda: in the command is supposed to help that, but it is not helping. ![]() I have a long way to go, but I am caught up on a couple items that if I get figured out will set me on the right path. I have been rummaging through tutorials and youtube videos to learn stuff. So I am very new to programming, I have set a goal of creating a simple file for tracking material prices that I use often. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |