-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpytoolbar.py
More file actions
113 lines (66 loc) · 2.69 KB
/
Copy pathpytoolbar.py
File metadata and controls
113 lines (66 loc) · 2.69 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
from tkinter import *
from PIL import Image, ImageTk
class TkInterEx:
@staticmethod
def quit_app(event=None):
root.quit()
def on_fav_food_select(self, event=None):
lb_widget = event.widget
index = int(lb_widget.curselection()[0])
lb_value = lb_widget.get(index)
self.fav_food_label['text'] = "I'll get you " + lb_value
def __init__(self, root):
root.title("Toolbar Example")
menubar = Menu(root)
file_menu = Menu(root, tearoff=0)
file_menu.add_command(label="Open")
file_menu.add_command(label="Save")
file_menu.add_command(label="Quit", command=self.quit_app)
menubar.add_cascade(label="File", menu=file_menu)
#toolbar
toolbar = Frame(root, bd=1, relief=RAISED)
open_img = Image.open("open.png")
save_img = Image.open("disk.png")
exit_img = Image.open("exit.png")
open_icon = ImageTk.PhotoImage(open_img)
save_icon = ImageTk.PhotoImage(save_img)
exit_icon = ImageTk.PhotoImage(exit_img)
open_button = Button(toolbar, image=open_icon)
save_button = Button(toolbar, image=save_icon)
exit_button = Button(toolbar, image=exit_icon)
open_button.image = open_icon
save_button.image = save_icon
exit_button.image = exit_icon
open_button.pack(side=LEFT, padx=2, pady=2)
save_button.pack(side=LEFT, padx=2, pady=2)
exit_button.pack(side=LEFT, padx=2, pady=2)
toolbar.pack(side=TOP, fill=X)
root.config(menu=menubar)
lb_frame = LabelFrame(root, text="Food Options", padx=5, pady=5)
self.fav_food_label =Label(lb_frame, text="What is your favorite food")
self.fav_food_label.pack()
list_box = Listbox(lb_frame)
list_box.insert(1, "Spaghetti")
list_box.insert(2, "Pizza")
list_box.insert(3, "Burgers")
list_box.insert(4, "Hot Dogs")
list_box.bind('<<ListBoxSelect>>', self.on_fav_food_select)
list_box.pack()
lb_frame.pack()
sb_frame = Frame(root)
quantity_label = Label(sb_frame,
text="How many do you want")
quantity_label.pack()
spin_box = Spinbox(sb_frame, from_=1, to=5)
spin_box.pack()
extras_label = Label(sb_frame, text="Add on Item")
extras_label.pack()
extras_spin_box = Spinbox(sb_frame, values=('French Fries',
'Onion Rings',
'Tater Tots'))
extras_spin_box.pack()
sb_frame.pack()
root = Tk()
root.geometry("600x550")
app = TkInterEx(root)
root.mainloop()