-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathq02.py
67 lines (56 loc) · 2.54 KB
/
q02.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
# Latin translator
import tkinter
class LatinTranslatorGUI:
def __init__(self):
# create the main window
self.main_window=tkinter.Tk()
# set the title
self.main_window.title("Latin to English Translator")
# create three frames.
self.top_frame=tkinter.Frame(self.main_window)
self.mid_frame=tkinter.Frame(self.main_window)
self.bottom_frame=tkinter.Frame(self.main_window)
# we need a StringVar object to associate with
# an output label
self.translation1=tkinter.StringVar()
self.translation2=tkinter.StringVar()
self.translation3=tkinter.StringVar()
# create labels for each button
self.translation_label1=tkinter.Label(self.top_frame, bg="green", fg="white", \
textvariable=self.translation1)
self.translation_label2=tkinter.Label(self.mid_frame, bg="green", fg="white", \
textvariable=self.translation2)
self.translation_label3=tkinter.Label(self.bottom_frame, bg="green", fg="white", \
textvariable=self.translation3)
# create button widgets on the top frame
self.b1=tkinter.Button(self.top_frame,\
text="sinister",\
command=self.answer1)
self.b2=tkinter.Button(self.mid_frame,\
text="dexter",\
command=self.answer2)
self.b3=tkinter.Button(self.bottom_frame,\
text="medium",\
command=self.answer3)
# pack the buttons and displays
self.b1.pack(side="left")
self.b2.pack(side="left")
self.b3.pack(side="left")
self.translation_label1.pack(side="right")
self.translation_label2.pack(side="right")
self.translation_label3.pack(side="right")
# pack the frames
self.top_frame.pack()
self.mid_frame.pack()
self.bottom_frame.pack()
# enter the mainloop.
self.main_window.mainloop()
# setter functions for each translation
def answer1(self):
self.translation1.set("left")
def answer2(self):
self.translation2.set("right")
def answer3(self):
self.translation3.set("center")
# create an instance of LatinTranslatorGUI
example = LatinTranslatorGUI()