Advanced Python Class - 2
Advanced Python Class - 2
TKINTER PACKGAGE
Checkbox Example 1:
CheckVar1 = IntVar()
CheckVar2 = IntVar()
CheckVar3 = IntVar()
Label(a, text="").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:
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:
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()
label = Label(root)
label.pack()
root.mainloop()
DROPDOWN LIST EXAMPLE 1:
win= Tk()
win.geometry("715x250")
menu= StringVar()
drop.pack()
win.mainloop()
ws = Tk()
ws.title('PythonGuides')
ws.geometry('400x300')
ws.config(bg='#BF7C41')
def change_color(choice):
choice = variable.get()
dropdown.config(bg=choice)
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()
ws = Tk()
ws.title('PythonGuides')
ws.geometry('400x300')
ws.config(bg='#BF7C41')
def change_color(choice):
choice = variable.get()
dropdown.config(bg=choice)
variable = StringVar()
variable.set("red")
dropdown.config(width=10)
dropdown.config(height=2)
dropdown.config(bg='light blue')
dropdown.pack(expand=True)
ws.mainloop()