From 50736928e4d0a9e54a2a00d665d3a777fabbe2d6 Mon Sep 17 00:00:00 2001 From: Logen Kain Date: Wed, 10 May 2017 15:03:47 -0700 Subject: [PATCH] Python: added labg --- python/labg/lab_g_Joseph_Green.py | 56 +++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 python/labg/lab_g_Joseph_Green.py diff --git a/python/labg/lab_g_Joseph_Green.py b/python/labg/lab_g_Joseph_Green.py new file mode 100644 index 0000000..5b1aff8 --- /dev/null +++ b/python/labg/lab_g_Joseph_Green.py @@ -0,0 +1,56 @@ +import tkinter +from tkinter import ttk + +class Adder(ttk.Frame): + def __init__(self, parent, *args, **kwargs): + ttk.Frame.__init__(self, parent, *args, **kwargs) + self.root = parent + self.init_gui() + + def on_quit(self): + self.root.destroy() + + + def calculate(self): + num1 = int(self.num1_entry.get()) + num2 = int(self.num2_entry.get()) + num3 = num1 + num2 + self.answer_label['text'] = num3 + + def init_gui(self): + self.root.title("Number Adder") + + self.grid(column=0, row=0, sticky='nsew') + + + self.num1_entry = ttk.Entry(self, width=5) + self.num1_entry.grid(column=1, row=2) + + self.num2_entry = ttk.Entry(self, width=5) + self.num2_entry.grid(column=3, row=2) + + self.calc_button = ttk.Button(self, text='Calculate', command=self.calculate) + self.calc_button.grid(column=0, row=3, columnspan=2) + + self.quit_button = ttk.Button(self, text='Quit', command=self.on_quit) + self.quit_button.grid(column=2, row=3, columnspan=2) + + self.answer_frame = ttk.LabelFrame(self, text='Answer', height=100) + self.answer_frame.grid(column=0, row=4, columnspan=4, sticky='nesw') + + self.answer_label = ttk.Label(self.answer_frame, text='') + self.answer_label.grid(column=0, row=0) + + ttk.Label(self, text='Number Adder').grid(column=0, row=0, columnspan=4) + ttk.Label(self, text='Number One:').grid(column=0, row=2, sticky='w') + ttk.Label(self, text='Number Two:').grid(column=2, row=2, sticky='w') + + ttk.Separator(self, orient='horizontal').grid(column=0, row=1, columnspan=4, sticky='ew') + for child in self.winfo_children(): + child.grid_configure(padx=5, pady=5) + +#if this is the main script +if __name__ == '__main__': + root = tkinter.Tk() + Adder(root) + root.mainloop()