forked from flatplanet/Intro-To-TKinter-Youtube-Course
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathddrops.py
86 lines (72 loc) · 1.64 KB
/
ddrops.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
from tkinter import *
from tkinter import ttk
root = Tk()
root.title('Codemy.com - Dependent Dropdowns')
root.iconbitmap('c:/gui/codemy.ico')
root.geometry("500x400")
# Creating a list of sizes
sizes = [
"Small",
"Medium",
"Large"
]
# Create a list of colors
small_colors = [
"Red",
"Green",
"Blue",
"Black"
]
medium_colors = [
"Red",
"Green"
]
large_colors = [
"Blue",
"Black"
]
def pick_color(e):
if my_combo.get() == "Small":
color_combo.config(value=small_colors)
color_combo.current(0)
if my_combo.get() == "Medium":
color_combo.config(value=medium_colors)
color_combo.current(0)
if my_combo.get() == "Large":
color_combo.config(value=large_colors)
color_combo.current(0)
# Create a drop box
my_combo = ttk.Combobox(root, value=sizes)
my_combo.current(0)
my_combo.pack(pady=20)
# bind the combobox
my_combo.bind("<<ComboboxSelected>>", pick_color)
# Color Combo box
color_combo = ttk.Combobox(root, value=[" "])
color_combo.current(0)
color_combo.pack(pady=20)
# Frame
my_frame = Frame(root)
my_frame.pack(pady=50)
# List boxes
my_list1 = Listbox(my_frame)
my_list2 = Listbox(my_frame)
my_list1.grid(row=0, column=0)
my_list2.grid(row=0, column=1, padx=20)
def list_color(e):
my_list2.delete(0, END)
if my_list1.get(ANCHOR) == "Small":
for item in small_colors:
my_list2.insert(END, item)
if my_list1.get(ANCHOR) == "Medium":
for item in medium_colors:
my_list2.insert(END, item)
if my_list1.get(ANCHOR) == "Large":
for item in large_colors:
my_list2.insert(END, item)
# add items to list1
for item in sizes:
my_list1.insert(END, item)
# Bind The Listbox
my_list1.bind("<<ListboxSelect>>", list_color)
root.mainloop()