Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. from tkinter import *
  2.  
  3.  
  4. class Calculator(Frame):
  5. def __init__(self, t):
  6. self.t = t
  7. super().__init__(self.t)
  8.  
  9. self.t.title('Calculator')
  10. self.grid(rows=4, columns=4, padx=20, pady=20)
  11.  
  12. self.start_interface()
  13. self.bindKeys()
  14.  
  15. def start_interface(self):
  16. font = ('Calibri', 20, 'normal')
  17.  
  18. self.a_val = StringVar('')
  19. self.a = Entry(self, font=font, textvariable=self.a_val)
  20. self.a.grid(row=1, column=1, columnspan=2)
  21.  
  22. self.b_val = StringVar('')
  23. self.b = Entry(self, font=font, textvariable=self.b_val)
  24. self.b.grid(row=1, column=3, columnspan=2)
  25.  
  26. self.button_plus = Button(self, text="+", command=lambda: self.calc('+'))
  27. self.button_plus.grid(row=2, column=1)
  28.  
  29. self.button_minus = Button(self, text="-", command=lambda: self.calc('-'))
  30. self.button_minus.grid(row=2, column=2)
  31.  
  32. self.button_mult = Button(self, text="*", command=lambda: self.calc('*'))
  33. self.button_mult.grid(row=2, column=3)
  34.  
  35. self.button_div = Button(self, text="/", command=lambda: self.calc('/'))
  36. self.button_div.grid(row=2, column=4)
  37.  
  38. def bindKeys(self):
  39. print('foo')
  40. # self.t.bind('<Control_L>', self.plus)
  41. # self.t.bind('<Control_R>', self.minus)
  42. # self.t.bind('<Alt_L>', self.div)
  43. # self.t.bind('<Shift_L>', self.mult)
  44.  
  45. # "https://pastebin.com/0vGT4BzY"
  46.  
  47. def calc(self, operation):
  48. a = int(self.a_val.get())
  49. b = int(self.b_val.get())
  50. if operation == '+':
  51. print(a + b)
  52. elif operation == '-':
  53. print(a - b)
  54. elif operation == '*':
  55. print(a * b)
  56. else:
  57. print(a / b)
  58.  
  59.  
  60. calc = Calculator(Tk())
  61. mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement