";require "../templates/head_jq_bs4.php";echo "
";$img_path="..";require "top-link-tkinter.php";require "templates/top_bs4.php"; echo "| Treeview | Displaying records from MySQL database in Tkinter window using Treeview |
| Delete | Deleting selected row from MySQL table and Treeview |
| Pagination | Pagination of records from MySQL table using Treeview |
| Paging | Pagination of records of MySQL table using Tkinter window |
| record display | Displaying record in a Tkinter window by taking user input as row id |
| record update | Select-Edit-Update row by using Treeview |
| Image display | Displaying Binary data from MySQL Blob column. |
| Image display | Displaying all records with Images from MySQL Blob column. |
| Image add | Inserting uploaded image to Blob column of MySQL table |
| Image add | Adding data to student table with Photo using Blob column of MySQL table |
| Image Update | Updating user uploaded image in MySQL Blob column |
| record add | Adding user entered data through Tkinter window to MySQL table |
| Login | System for Login with add user and listing users with delete option |
| Random | Display Random record from MySQL or SQLite Database. |
| Ticket No. | Generate unique string id using date after inserting record |
import mysql.connector # Importing the MySQL connector librarymy_connect = mysql.connector.connect( host="localhost", # Hostname of the MySQL server user="userid", # MySQL username passwd="password", # MySQL password database="database_name" # Name of the database to connect)####### end of connection ####my_conn = my_connect.cursor() # Create a cursor object to execute SQL queriesWe will use my_conn in our further script as the connection object to get our records. my_conn = my_connect.cursor() # Create a cursor object for executing SQL queriesmy_conn.execute("SELECT * FROM student limit 0,10") # Execute the SQL query to fetch 10 rowsi = 0 # Initialize row counterfor student in my_conn: # Iterate through the result set for j in range(len(student)): # Iterate through each column in a row print(student[j], end='') # Print column value without line break i = i + 1 # Increment the row counter print() # Line break at the end of one rowThis will print 10 rows of records from student table. import mysql.connectorimport tkinter as tkfrom tkinter import *my_w = tk.Tk()my_w.geometry("400x250") # width and height of the windowmy_connect = mysql.connector.connect( host="localhost", # Database host user="id", # Database user passwd="password", # Database password database="my_db" # Database name)my_conn = my_connect.cursor() # Cursor for executing queries####### end of connection ####my_conn.execute("SELECT * FROM student limit 0,10")i = 0for student in my_conn: for j in range(len(student)): e = Entry(my_w, width=10, fg='blue') e.grid(row=i, column=j) e.insert(END, student[j]) i = i + 1my_w.mainloop() from sqlalchemy import create_engine, textmy_conn = create_engine("mysql+mysqldb://id:pw@localhost/my_db")my_conn = my_conn.connect() # connection object, connection stringimport tkinter as tkfrom tkinter import *my_w = tk.Tk() # parent windowmy_w.geometry("400x250") # width and height of window####### end of connection ####r_set = my_conn.execute(text("SELECT * FROM student limit 0,10"))i = 0for student in r_set: for j in range(len(student)): e = Entry(my_w, width=10, fg='blue') e.grid(row=i, column=j) e.insert(END, student[j]) i = i + 1my_w.mainloop()
Using Label in place of Entry in above code. for student in r_set: for j in range(len(student)): e = Label(my_w,width=10, text=student[j]) e.grid(row=i, column=j) #e.insert(END, student[j]) i=i+1
We can add border to each cell by using borderwidth=2, relief='ridge' and align the text to left by using anchor='w'. e = Label(my_w, width=10, text=student[j], borderwidth=2, relief='ridge', anchor="w") 

e=Label(my_w,width=10,text='id',borderwidth=2, relief='ridge',anchor='w',bg='yellow')e.grid(row=0,column=0)e=Label(my_w,width=10,text='Name',borderwidth=2, relief='ridge',anchor='w',bg='yellow')e.grid(row=0,column=1)e=Label(my_w,width=10,text='Class',borderwidth=2, relief='ridge',anchor='w',bg='yellow')e.grid(row=0,column=2)e=Label(my_w,width=10,text='mark',borderwidth=2, relief='ridge',anchor='w',bg='yellow')e.grid(row=0,column=3)e=Label(my_w,width=10,text='Gender',borderwidth=2, relief='ridge',anchor='w',bg='yellow')e.grid(row=0,column=4)i=1e = Label(my_w,width=10, text='id', borderwidth=2,relief='ridge', anchor='w', bg='yellow')e.grid(row=0, column=0) e = Label(my_w, width=10, text='Name', borderwidth=2, relief='ridge', anchor='w', bg='yellow') e.grid(row=0, column=1) e = Label(my_w, width=10, text='Class', borderwidth=2, relief='ridge', anchor='w', bg='yellow') e.grid(row=0, column=2) e = Label(my_w, width=10, text='mark', borderwidth=2, relief='ridge', anchor='w', bg='yellow') e.grid(row=0, column=3) e = Label(my_w, width=10, text='Gender', borderwidth=2, relief='ridge', anchor='w', bg='yellow') e.grid(row=0, column=4) i = 1