Tkinter to read student id & display matching record from SQLite database table by executing query



Tkinter to read student id & display matching record from SQLite database table by executing query

Tkinter to read student id & display matching record from SQLite database table by executing query

00:42 Create table with sample records copy the code
01:30 connection to database and layout
04:36 connecting click event of the button to the function
06:28 Checking how the ID is received inside the function and displayed.
07:56 getting data from SQLite Database using query
11:17 adding the except block to handle error if any
11:55 Final demo by entering the student id

We can use SQLAlchemy or SQLite3 to connect to SQLite database. Inside the SQLite database we have student table with sample rows of data. ( link is below to create table )
We will create one connection string by using SQLAlchemy or SQLite3 ( all codes are available to download )

We are using one tkinter text widget to collect student id as entered by user. Here we will read the id and on click of a button we will pass this id as parameter to a function my_details().

Inside this function we will first check the id is integer or string. As we expect an integer as input so we will generate error message by using try except code block .
Using this ID we will prepare a query to select the record by using WHERE clause. We are using parameterized query by using placeholder and sending the data separately.
Using the connection string we will collect the matching row of data from student table and display the same in our Tkinter Label widget ( l2 )
If there is no matching record present then we will get None as output.

Download the source code from here
https://www.plus2net.com/python/tkinter-sqlite-id.php

Connect or create the SQLite database, create student table and add sample records
https://www.plus2net.com/python/sqlite-connection.php#data_student

#SQLitePython #TkinterSQLite #SQLiteQuery #PythonData #SQLiteConnection #Datahandling

Comments are closed.