Advertisement
Guest User

Untitled

a guest
May 28th, 2018
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. from tkinter import *
  2. from tkinter.ttk import *
  3.  
  4.  
  5. class HelloGui:
  6. def __init__(self, parent):
  7. """docstring showing innit function"""
  8. ops = ['+', '-', '*']
  9. self.name_entry = Entry(parent)
  10. self.name_entry.grid(row=0, column=0)
  11. self.name_entry2 = Entry(parent)
  12. self.name_entry2.grid(row=0, column=2)
  13. self.combo = Combobox(parent, values=ops)
  14. self.combo.grid(row=0, column=1)
  15. self.combo.bind('<<ComboboxSelected>>', self.calculator)
  16. self.combo.current(0)
  17.  
  18.  
  19.  
  20. self.button = Button(parent, text='Calculate', command=self.calculator)
  21. self.button.grid(row=1, column=1)
  22. self.message_label = Label(parent, text='')
  23. self.message_label.grid(row=0, column=4)
  24. self.return_value = Label(parent, text='=')
  25. self.return_value.grid(row=0, column=3)
  26.  
  27. def calculator(self):
  28. """shows message"""
  29. num = self.name_entry.get()
  30. num1 = self.name_entry2.get()
  31. operator = self.combo.get()
  32. maths = int(num) + operator + int(num1)
  33. self.message_label['text'] = maths
  34.  
  35.  
  36.  
  37. def main():
  38. window = Tk()
  39. gui = HelloGui(window)
  40. window.mainloop()
  41.  
  42. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement