Advertisement
Felanpro

calculator in progress

Nov 7th, 2016
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.49 KB | None | 0 0
  1. from tkinter import *
  2.  
  3. root = Tk()
  4. root.title("Calculator")
  5. root.geometry("220x550")
  6.  
  7. def plus_button_function():
  8.     global plus_first
  9.     plus_first = int(e.get())
  10.     e.delete(0, END)
  11.  
  12. def equal_button_function():
  13.     global plus_second
  14.     plus_second = int(e.get())
  15.     plus_sum = plus_first + plus_second
  16.     e.insert(0, plus_sum)
  17.  
  18. def b1_function():
  19.     e.insert(0, "1")
  20.  
  21. def b2_function():
  22.     e.insert(0, "2")
  23.  
  24. def b3_function():
  25.     e.insert(0, "3")
  26.  
  27. def b4_function():
  28.     e.insert(0, "4")
  29.  
  30. def b5_function():
  31.     e.insert(0, "5")
  32.  
  33. def b6_function():
  34.     e.insert(0, "6")
  35.  
  36. def b7_function():
  37.     e.insert(0, "7")
  38.  
  39. def b8_function():
  40.     e.insert(0, "8")
  41.    
  42. def b9_function():
  43.     e.insert(0, "9")
  44.  
  45. e = Entry(root)
  46. equal_button = Button(root, text = "=", command = equal_button_function)
  47.  
  48. b1 = Button(root, text = "1", command = b1_function)
  49. b2 = Button(root, text = "2", command = b2_function)
  50. b3 = Button(root, text = "3", command = b3_function)
  51. b4 = Button(root, text = "4", command = b4_function)
  52. b5 = Button(root, text = "5", command = b5_function)
  53. b6 = Button(root, text = "6", command = b6_function)
  54. b7 = Button(root, text = "7", command = b7_function)
  55. b8 = Button(root, text = "8", command = b8_function)
  56. b9 = Button(root, text = "9", command = b9_function)
  57.  
  58. plus_button = Button(root, text = "+", command = plus_button_function)
  59.  
  60. e.grid(row = 0, column = 0)
  61. equal_button.grid(row = 0, column = 1)
  62. b1.grid(row = 1, column = 1)
  63.  
  64. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement