0% found this document useful (0 votes)
20 views7 pages

Python Lab - GUI Programs-1

The document provides a series of Python GUI programs using the Tkinter library, demonstrating various widgets such as Label, Entry, Button, Canvas, Checkboxes, and Radio buttons. Each program includes code snippets and a brief description of its functionality, such as creating feedback forms and biodata forms. The examples illustrate basic GUI concepts and how to implement them in Python.

Uploaded by

radwanaeef
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views7 pages

Python Lab - GUI Programs-1

The document provides a series of Python GUI programs using the Tkinter library, demonstrating various widgets such as Label, Entry, Button, Canvas, Checkboxes, and Radio buttons. Each program includes code snippets and a brief description of its functionality, such as creating feedback forms and biodata forms. The examples illustrate basic GUI concepts and how to implement them in Python.

Uploaded by

radwanaeef
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Python GUI Programs

­1) GUI Program to illustrate Label widget

Program:
from tkinter import *
window=Tk()
window.title("Label Widget")
window.geometry("400x200")

l=Label( window, text="This is a


Label",fg="blue",bg="yellow",width=40,height=2)
l.pack()

window.mainloop()
Output:

2) GUI Program to illustrate Entry Box widget

Program:
from tkinter import *
window=Tk()
window.title("Entry Widget")
window.geometry("400x200")

ent = Entry(window, fg="red", bg="white",


width=20,font=("Times",20))
ent.pack()
window.mainloop()
Output:

1
3) GUI Program to illustrate button and message box widget

Program:
from tkinter import *
from tkinter import messagebox

def clickaction( ):
messagebox.showinfo( "Click Command Action","Button
clicked")

window=Tk()
window.title("Button and Message Box")
window.geometry("300x100")

b1=Button( window, text="Click", fg="white", bg="blue",


width=10, height=2, command=clickaction)
b1.place(x=50, y=30)

b2=Button(window, text="Exit", fg="white", bg="red", width=10,


height=2,command=window.destroy)
b2.place(x=180, y=30)

window.mainloop()
Output:

4) GUI Program to create a simple feedback form


Program:
from tkinter import *
window=Tk()
window.title("FEEDBACK")
window.geometry("300x250")
lab=Label( window, text="FEEDBACK FORM",font=('Times', 20))
lab.pack()

lab1=Label( window, text="Name")


lab1.place(x=30, y=60)

2
ent1=Entry(window,fg="red")
ent1.place(x=150, y=60)

lab3=Label( window, text="Phone No.")


lab3.place(x=30, y=90)
ent3=Entry(window,fg="red")
ent3.place(x=150, y=90)

lab2=Label( window, text="Message")


lab2.place(x=30, y=120)
ent2=Entry(window,fg="red")
ent2.place(x=150, y=120)

but1=Button( window, text="SEND")


but1.place(x=150, y=150)
window.mainloop()

Output:

5) GUI Program to illustrate Canvas


Program:
from tkinter import *
window = Tk()
window.title("Canvas")

can = Canvas(window, bg="yellow",height=250, width=300)

line = can.create_line(108, 120,320, 40,fill="green")

3
arc = can.create_arc(180, 150, 80,210,
start=0,extent=220,fill="red")
oval = can.create_oval(80, 30, 140,150,fill="blue")
can.pack()

window.mainloop()
Output:

6) Program to illustrate Checkbox and Radio button


Program:
from tkinter import *
window = Tk()
window.title("CheckBox and Radio Button")
window.geometry("400x200")

lab1=Label( window, text="Programming Language


",fg="blue",height=1)
lab1.place(x=20,y=30)

chkvar1 = IntVar()
chkvar2 = IntVar()
chkvar3 = IntVar()
chk1 = Checkbutton(window, text='Python',variable=chkvar1,
onvalue=1, offvalue=0)
chk1.place(x=200,y=30)
chk2 = Checkbutton(window, text='C++',variable=chkvar2,
onvalue=1, offvalue=0)
chk2.place(x=280,y=30)
chk3 = Checkbutton(window, text='PHP',variable=chkvar3,
onvalue=1, offvalue=0)
chk3.place(x=330,y=30)

lab2=Label( window, text="Operating System


",fg="blue",height=1)
lab2.place(x=20,y=70)

4
radvar = IntVar()
rad1 = Radiobutton(window, text="Windows", variable=radvar,
value=1)
rad1.place(x=200,y=70)
rad2 = Radiobutton(window, text="Linux", variable=radvar,
value=2)
rad2.place(x=280,y=70)

window.mainloop()

Output:

7.GUI Program to create a biodata form


Program:
from tkinter import *
window = Tk()
window.title("Biodata")
window.geometry("400x300")

lab=Label( window, text="BIODATA",font=('Times', 20))


lab.pack()

lab1=Label( window, text="Name",fg="blue",font=('Times', 12))


lab1.place(x=30, y=60)
ent1=Entry(window,fg="red")
ent1.place(x=150, y=60)

lab3=Label( window, text="Phone No.",fg="blue",font=('Times',


12))
lab3.place(x=30, y=90)
ent3=Entry(window,fg="red")
ent3.place(x=150, y=90)

5
lab2=Label( window, text="Email",fg="blue",font=('Times', 12))
lab2.place(x=30, y=120)
ent2=Entry(window,fg="red")
ent2.place(x=150, y=120)

lab1=Label( window, text="Hobbies


",fg="blue",height=1,font=('Times', 12))
lab1.place(x=30,y=150)

chkvar1 = IntVar()
chkvar2 = IntVar()
chkvar3 = IntVar()
chk1 = Checkbutton(window, text='Cricket',variable=chkvar1,
onvalue=1, offvalue=0)
chk1.place(x=150,y=150)
chk2 = Checkbutton(window, text='Football',variable=chkvar2,
onvalue=1, offvalue=0)
chk2.place(x=230,y=150)
chk3 = Checkbutton(window, text='Reading',variable=chkvar3,
onvalue=1, offvalue=0)
chk3.place(x=300,y=150)

lab2=Label( window, text="Gender


",fg="blue",height=1,font=('Times', 12))
lab2.place(x=30,y=180)
radvar = IntVar()
rad1 = Radiobutton(window, text="Male", variable=radvar,
value=1)
rad1.place(x=150,y=180)
rad2 = Radiobutton(window, text="Female", variable=radvar,
value=2)
rad2.place(x=200,y=180)

but1=Button( window, text="SAVE")


but1.place(x=150, y=210)

window.mainloop()

Output:

6
7

You might also like