0% found this document useful (0 votes)
33 views6 pages

Advanced Python Class - 2

The document provides examples of using the Tkinter package in Python for creating GUI applications. It includes code snippets for checkboxes, radio buttons, and dropdown lists, demonstrating how to implement these features and handle user interactions. Each example is self-contained and showcases different functionalities of Tkinter.

Uploaded by

nazar
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)
33 views6 pages

Advanced Python Class - 2

The document provides examples of using the Tkinter package in Python for creating GUI applications. It includes code snippets for checkboxes, radio buttons, and dropdown lists, demonstrating how to implement these features and handle user interactions. Each example is self-contained and showcases different functionalities of Tkinter.

Uploaded by

nazar
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/ 6

TECHMIND INFOTECH

Computer Education and Project Training Centre


(A Government Approved Institution)
Sri Ram Towers 2nd Floor, Santhanathapuram 6th Street, Pudukkottai
Cell: 7293 52 7293 Email: [email protected]

ADVANCED PYTHON CLASS - 2

TKINTER PACKGAGE
Checkbox Example 1:

from tkinter import *


import tkinter.messagebox
a= Tk()
a.geometry("400x400")
def music():
tkinter.messagebox.showinfo(title="music",message="you select music")
def video():
tkinter.messagebox.showinfo(title="video",message="you select video")
def photo():
tkinter.messagebox.showinfo(title="photo",message="you select photo")

CheckVar1 = IntVar()
CheckVar2 = IntVar()
CheckVar3 = IntVar()

C1 = Checkbutton(a, text = "Music",activebackground="black" ,


activeforeground="white",bg="green",bd=10,variable = CheckVar1,onvalue = 1, offvalue =
0,command = music).pack()

Label(a, text="").pack()

C2 = Checkbutton(a, text = "video",activebackground="black"


,activeforeground="white",bg="green",bd=10,variable = CheckVar2,onvalue = 1, offvalue =
0,command = video).pack()

Label(a, text="").pack()
C3 = Checkbutton(a, text = "photo",activebackground="black" ,
activeforeground="white",bg="green",bd=10,variable = CheckVar3,onvalue = 1, offvalue =
0,command = photo).pack()

a.mainloop()

Checkbox Example 2:

from tkinter import *


from tkinter import messagebox
root =Tk()
root.geometry('300x200')
root.title('Checkbox Demo')

def display():
messagebox.showinfo(title='Result', message=a.get())

a = StringVar()

Checkbutton(root,
text='I agree',
command=display,
variable=a,
onvalue='agree',
offvalue='disagree').pack()

root.mainloop()
RADIO BUTTON EXAMPLE:

from tkinter import *

def sel():
selection = "You selected the option " + str(var.get())
label.config(text = selection)

root = Tk()
var = IntVar()
R1 = Radiobutton(root, text="Option 1", variable=var, value=1,
command=sel)
R1.pack()

R2 = Radiobutton(root, text="Option 2", variable=var, value=2,


command=sel)
R2.pack()

R3 = Radiobutton(root, text="Option 3", variable=var, value=3,


command=sel)
R3.pack()

label = Label(root)
label.pack()
root.mainloop()
DROPDOWN LIST EXAMPLE 1:

from tkinter import *

win= Tk()

win.geometry("715x250")

menu= StringVar()

menu.set("Select Any Language")

drop= OptionMenu(win, menu,"C++", "Java","Python","JavaScript","Rust","GoLang")

drop.pack()

win.mainloop()

DROP DOWN LIST EXAMPLE 2:

from tkinter import *

from tkinter import messagebox

ws = Tk()

ws.title('PythonGuides')

ws.geometry('400x300')

ws.config(bg='#BF7C41')

def change_color(choice):

choice = variable.get()

dropdown.config(bg=choice)

messagebox.showinfo("Xiith.com", "You selected " + choice)

color_list = ['aquamarine', 'light blue', 'olive drab', 'gray']


variable = StringVar()

variable.set(color_list[1])

dropdown = OptionMenu(

ws,

variable,

*color_list,

command=change_color

dropdown.config(width=10)

dropdown.config(height=2)

dropdown.config(bg='light blue')

dropdown.pack(expand=True)

ws.mainloop()

DROPDOWN LIST EXAMPLE 3:

from tkinter import *

from tkinter import messagebox

ws = Tk()

ws.title('PythonGuides')

ws.geometry('400x300')

ws.config(bg='#BF7C41')

def change_color(choice):

choice = variable.get()
dropdown.config(bg=choice)

messagebox.showinfo("Xiith.com", "You selected " + choice)

variable = StringVar()

variable.set("red")

dropdown = OptionMenu(ws,variable,'red','green','yellow', command=change_color)

dropdown.config(width=10)

dropdown.config(height=2)

dropdown.config(bg='light blue')

dropdown.pack(expand=True)

ws.mainloop()

You might also like