Showing Data in MySql Database in ListBox - The Advantages of Learning Python Programming for Beginners: A Comprehensive Guide

Latest

Dive into the world of Python programming with our comprehensive resources

Music

logo

Sunday, March 26, 2023

Showing Data in MySql Database in ListBox

 In this article, I will show the data in the worldclassics table in the Mysql database in the Listbox.

First, let's add the Mysql class as follows. Then I add the connector that will provide the connection to the Mysql Database.

 


 

 

 

 

 

 

 

 

Figure 1

 

import mysql.connector

from tkinter import *

 

con1 = mysql.connector.connect(

    host="localhost",

    user="root",

    password="2344",

    database="book"

)

 

cur = con1.cursor()

 

 

root= Tk()

root.geometry("600x400")

root.title("search...bs")

 

 

# create listbox object

listbox = Listbox(root,height = 70,

                  width = 70,

                  bg = "grey",

                  activestyle = 'dotbox',

                  font = "Helvetica",

                  fg = "yellow")

 

 

cur1 = con1.cursor()

 

cur1.execute("Select * From worldclassics")

 

rows = cur1.fetchall()   

 

for row in rows:

 print(row)

 listbox.insert(END, row)

con1.close()

 

listbox.pack()

 

root.mainloop()

 

 

Happy coding.

No comments:

Post a Comment

Featured post

Python Introduction

What is Python? Python is an interpreted, object-oriented, high-level programming language with dynamic semantics. Its high-level built ...