Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. from tkinter import *
  2. root = Tk()
  3.  
  4. first_row = Frame(root)
  5. second_row = Frame(root)
  6. third_row = Frame(root)
  7. fourth_row = Frame(root)
  8. fifth_row = Frame(root)
  9.  
  10.  
  11. e1 = Entry(first_row, width=34)
  12.  
  13. b7 = Button(second_row, text="7", width=6, command=lambda s="7": addSymbol(s))
  14. b8 = Button(second_row, text="8", width=6, command=lambda s="8": addSymbol(s))
  15. b9 = Button(second_row, text="9", width=6, command=lambda s="9": addSymbol(s))
  16. button_plus = Button(second_row, text="+", width=6, command=lambda a="+": chooseAction(a))
  17.  
  18. b4 = Button(third_row, text="4", width=6, command=lambda s="4": addSymbol(s))
  19. b5 = Button(third_row, text="5", width=6, command=lambda s="5": addSymbol(s))
  20. b6 = Button(third_row, text="6", width=6, command=lambda s="6": addSymbol(s))
  21. button_sub = Button(third_row, text="-", width=6, command=lambda a="-": chooseAction(a))
  22.  
  23. b1 = Button(fourth_row, text="1", width=6, command=lambda s="1": addSymbol(s))
  24. b2 = Button(fourth_row, text="2", width=6, command=lambda s="2": addSymbol(s))
  25. b3 = Button(fourth_row, text="3", width=6, command=lambda s="3": addSymbol(s))
  26. button_mul = Button(fourth_row, text="*", width=6, command=lambda a="*": chooseAction(a))
  27.  
  28. b0 = Button(fifth_row, text="0", width=6, command=lambda s="0": addSymbol(s))
  29. button_res = Button(fifth_row, text="=", width=12)
  30. button_div = Butt
  31. on(fifth_row, text="/", width=6, command=lambda a="/": chooseAction(a))
  32.  
  33. def chooseAction(action):
  34. print(action)
  35. s1 = e1.get()
  36. #s2 = e2.get()
  37. #s3 = float(s1) + float(s2)
  38. #l['text'] = ''.join(str(s3))
  39.  
  40.  
  41. def addSymbol(symbol):
  42. e1.insert(END,symbol)
  43.  
  44.  
  45. first_row.pack()
  46. second_row.pack()
  47. third_row.pack()
  48. fourth_row.pack()
  49. fifth_row.pack()
  50.  
  51. e1.pack(side=LEFT)
  52.  
  53. b0.pack(side=LEFT)
  54. b1.pack(side=LEFT)
  55. b2.pack(side=LEFT)
  56. b3.pack(side=LEFT)
  57. b4.pack(side=LEFT)
  58. b5.pack(side=LEFT)
  59. b6.pack(side=LEFT)
  60. b7.pack(side=LEFT)
  61. b8.pack(side=LEFT)
  62. b9.pack(side=LEFT)
  63.  
  64. button_plus.pack(side=LEFT)
  65. button_sub.pack(side=LEFT)
  66. button_mul.pack(side=LEFT)
  67. button_res.pack(side=LEFT)
  68. button_div.pack(side=LEFT)
  69.  
  70. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement