How To Create Beautiful Python GUI Programming With Tkinter 2021?

python gui programming with tkinter

Python Tkinter Tutorial || Python GUI Programming With Tkinter

In the article I will teach you how to create a simple Python GUI Programming With Tkinter. The python programming have a lot of GUI library but Tkinter is the best framework or library to built custom GUI application. Using Tkinter you can built twice OS application.

It mean the Tkinter application run the multi operating system i.e Windows, Linux and MacOS. In the beginner when you start to learn Tkinter GUI application I recommended to you, you should have the basic knowledge of HTML (Hyper Text Markup Language) .

The Tkinter is the light weight and relatively framework as compare to other GUI library. In tkinter you can built a simple and and fast application. In Tkinter modern sheen is unnecessary. It make a compiling choice for building GUI program.

Creating Your Fist Python GUI Programming With Tkinter Using SQLite Database Integration.

Developing the database program in python here we integrated SQLite with python. SQLite is powerful database engine for organize the data.

Read my previous article how to create database in SQLite

In this program you will learn

  • Application Layout with geometry manager.
  • Work with Widgets such as command button, text box, label and picture.
  • Python Click functions.
  • SQLite Database

Python GUI Programming With Tkinter || Interface Design:

The first step for building GUI program in python using Tkinter is designing a interactive interface, So for this I will create a simple use signup interface first follow these simple and easy step.

Step 01 : Open Pycharm in you PC or laptop and create a new project.

Step 02 : Right click on the project window which is left side on the window and choose new and then click on python file.

python gui programming with tkinter

Step 03 : Enter the the of your file and then press enter.

python gui programming with tkinter

Step 04 : Copy the following code and paste in your file.

#Python GUI Programming With Tkinter
tkinter import * import sqlite3 import connection import tkinter.messagebox import cursor as cursor from PIL import Image, ImageTk root = Tk() root.geometry("500x500") root.title("USER LOGIN") image ="G:/Android/img/img_user.png") photo = ImageTk.PhotoImage(image) lab = Label(image=photo) lab.pack() menu = Menu(root) root.config(menu=menu) def exit1(): exit() def abt(): tkinter.messagebox.showinfo("Welcome to authors", "this is demo for menu fields") def ext_1(): exit() def add_student(): name1 = fn.get() lname = ln.get() dob = db.get() ct = country.get() pro = var_c1 gander = radio_var.get() connection.insert(name1, lname, dob, ct, pro, gander) tkinter.messagebox.showinfo("Welcome", 'User Successfully Save!!!') subm1 = Menu(menu) menu.add_cascade(label="File", menu=subm1) subm1.add_command(label="Exit", command=abt) subm2 = Menu(menu) menu.add_cascade(label="option", menu=subm2) subm2.add_command(label="Edit", command=abt) fn = StringVar() ln = StringVar() db = StringVar() country = StringVar() var_c1 = "Python" var_c2 = "Java" radio_var = StringVar() def printt(): first = fn.get() sec = ln.get() dob = db.get() c = country.get() var3 = var_c2, var_c1 var4 = radio_var.get() print(f"First Name Is {first} {sec}") print(f"Your D.O.B Is {dob}") print(f"Your Country Is {c}") print(f"your prog language Is {var3}") print(f"your gender Is {var4}") tkinter.messagebox.showinfo("Welcome", 'User Is Successfully Sign Up !!!') def abt(): tkinter.messagebox.askyesno(" Welcome ", 'this software developed by sadaqat hussain') label_0 = Label(root, text="USER LOGIN", relief="solid", width=20, font=("arial", 19, "bold")), y=53) label_1 = Label(root, text="first Name :", width=20, font=("arial", 10, "bold")), y=130) entry_1 = Entry(root, textvar=fn), y=135) label2 = Label(root, text="LastName :", width=20, font=("arial", 10, "bold")), y=180) entry_2 = Entry(root, textvar=ln), y=185) label3 = Label(root, text="DOB :", width=20, font=("arial", 10, "bold")), y=220) entry_3 = Entry(root, textvar=db), y=225) label4 = Label(root, text="Select Country :", width=20, font=("arial", 10, "bold")), y=260) list_1 = ['Pakistan', 'India', 'UAE', 'Iran', 'China'] droplist = OptionMenu(root, country, *list_1) country.set("Select Country") droplist.config(width=15), y=255) label3 = Label(root, text="prog lang :", width=20, font=("arial", 10, "bold")), y=335) c1 = Checkbutton(root, text="Java", variable=var_c1).place(x=235, y=300) c2 = Checkbutton(root, text="python", variable=var_c2).place(x=300, y=300) r1 = Radiobutton(root, text='Male', variable=radio_var, value='Male').place(x=230, y=336) r2 = Radiobutton(root, text='Female', variable=radio_var, value='Female').place(x=301, y=333) label3 = Label(root, text="gendre :", width=20, font=("arial", 10, "bold")), y=300) but_singup = Button(root, text="signup", width=12, bg='brown', fg='white', command=add_student).place(x=150, y=400) but_close = Button(root, text="quit", width=12, bg='brown', fg='white', command=exit1).place(x=280, y=400) root.mainloop()


This Post Has One Comment

Comments are closed.