In this lesson we are going to talk about TKinter MySQL Database, we want to learn how you can connect your tkinter application with mysql database.
First of all you need to download Wamp Server, because we are going to create our database in wamp server, after that create a database in the wamp server, you can give any name for your database, i have give tkdb.
TKinter Database
Also you need to install MySQLdb, MySQLdb is an interface to the popular MySQL database server that provides the Python database API. originally MySQLdb was for Python 2.7, but there another version of MySQLdb that is called MysqlClient, and it supports Python 3.0, at the writing of this article MysqlClient supports Python 3.0 up to 3.8, you can check their Documentation for more updates.
We have created a button with a label, because we want to check mysql database connectivity.
1
2
3
4
5
6
button=ttk.Button(self.label_frame,
text="Connection Status",command=self.db_connect)
button.grid(column=0,row=0)
self.label=ttk.Label(self.label_frame,text="")
self.label.grid(column=0,row=1)
Using this code we can connect our tkinter application to mysql database, you need to give host, username, password and database name in the parameters.
1
mdb.connect('localhost','root','','tkdb')
Run the complete code and click on the button this will be the result.
TKinter MySQL Database
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the ...
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.