Chapter 4: GUI Programming and Database
Connectivity Using Python
4.1 Introduction to GUI
A Graphical User Interface (GUI) allows users to interact with a computer using visual components
such as windows, icons, buttons, and menus.
4.2 Tkinter Basics
Tkinter is Python's standard library for GUI programming. A simple GUI can be created using Tk(),
widgets, and the mainloop() method.
Sample Code: Tkinter Window
from tkinter import *
root = Tk()
[Link]("My First GUI")
[Link]("400x300")
[Link]()
4.3 Connecting with MySQL
Python uses the [Link] module to connect with a MySQL database. Use pip to install it:
pip install mysql-connector-python
Sample Code: MySQL Connection
import [Link]
conn = [Link](
host="localhost",
user="root",
passwd="mypassword",
database="school"
)
print(conn)