Tkinter window to display row details from MySQL table based on the user input of record id
HTML-код
- Опубликовано: 5 сен 2024
- www.plus2net.c...
By entering id of the record we can get the full details of the student record. To display these details we will use widgets and place them on the window.
We need one button to read the id entered by user and pass the value to one function.
One label is used to display the output and error messages if any.
The input is also to be validated so if the input is not an integer then we will display a message asking the user to check input.
The components are placed in the window and the key part is the on click event of the button. On click of the button the data entered by the user is collected by using get() method and same is passed to the function my_details() as a parameter.
b1 = tk.Button(my_w, text='Show Details', width=15,bg='red',
command=lambda: my_details(t1.get('1.0',END)))
In above code the command option triggers the function my_details() by passing the user entered id at the text input t1.
Inside the function my_details() first we will convert the user input to integer by using int(). We will use one try , except block to generate error message if the user has not entered integer as input.
Inside the try block we will create query to access the database and get the record by using id as input. Here we will use parameterized query to pass id value separately.
Once the query is executed we will use fetchone() method to get the single record. This record we will display by using the string variable we created for the label l2. If any database error is generated then same can be displayed as we are using one try except block to execute the database management part.
Hello. Great Tutorial. I know I'm late, but could you kindly show how to do this into a treeview? Thanks
ruclips.net/video/mHpMFzi4NuI/видео.html
Download the source code from here. ( towards the end of the page )
www.plus2net.com/python/tkinter-mysql-id.php