Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.01 KB | None | 0 0
  1. import sys
  2. from tkinter import *
  3.  
  4. root = Tk()
  5. frame = Frame(root)
  6. frame.pack()
  7.  
  8. def clear():
  9. global operator
  10. operator=""
  11. text_Input.set("")
  12.  
  13. def buttonClick(numbers):
  14. global operator
  15. operator= operator+str(numbers)
  16. text_Input.set(operator)
  17.  
  18. def buttonEqual():
  19. global operator
  20. equal=str(eval(operator))
  21. text_Input.set(equal)
  22. operator=""
  23.  
  24. operator=""
  25. root.title("Calculator")
  26. text_Input =StringVar()
  27.  
  28.  
  29.  
  30. #DISPLAY
  31. def display():
  32. topframe = Frame(root)
  33. topframe.pack(side = TOP)
  34.  
  35. txtDisplay=Entry(frame, textvariable= text_Input, bd= 50, insertwidth= 0, font= 40)
  36. txtDisplay.pack(side= TOP)
  37.  
  38. #BOTTOM ROW OF NUMBERS AND FUNCTIONS
  39. def bot_row():
  40. frame4 = Frame(root)
  41. frame4.pack(side = TOP)
  42.  
  43. buttonzero= Button(frame4, padx= 44, pady= 15, bd=8, text= "0", fg="green",bg="red", command= lambda:buttonClick(0))
  44. buttonzero.pack(side =LEFT)
  45. buttonsubtract= Button(frame4, padx= 15, pady= 15, bd=8, text= "-", fg="green",bg="red", command= lambda:buttonClick("-"))
  46. buttonsubtract.pack(side =LEFT)
  47. buttonaddition= Button(frame4, padx= 13, pady= 15, bd=8, text= "+", fg="green",bg="red", command= lambda:buttonClick("+"))
  48. buttonaddition.pack(side =LEFT)
  49. buttonequal= Button(frame4, padx= 14, pady= 15, bd=8, text= "=", fg="green",bg="red", command= lambda:buttonEqual())
  50. buttonequal.pack(side =LEFT
  51. )
  52.  
  53.  
  54. #BOTTWO ROW OF NUMBERS AND FUNCTIONS
  55. def bottwo_row():
  56. frame3 = Frame(root)
  57. frame3.pack(side = TOP)
  58.  
  59. buttonone= Button(frame3,padx= 15, pady= 15, bd=8, text= "1", fg="green", bg="red", command= lambda:buttonClick(1))
  60. buttonone.pack(side =LEFT)
  61. buttontwo= Button(frame3,padx= 15, pady= 15, bd=8, text= "2", fg="green", bg="red", command= lambda:buttonClick(2))
  62. buttontwo.pack(side =LEFT)
  63. buttonthree= Button(frame3,padx= 15, pady= 15, bd=8, text= "3", fg="green", bg="red", command= lambda:buttonClick(3))
  64. buttonthree.pack(side =LEFT)
  65. buttonclosebracket= Button(frame3,padx= 15, pady= 15, bd=8, text= ")", fg="green", bg="red", command= lambda:buttonClick(")"))
  66. buttonclosebracket.pack(side =LEFT)
  67. buttondivision= Button(frame3, padx= 15, pady= 15, bd=8, text= "/", fg="green", bg="red", command= lambda:buttonClick("/"))
  68. buttondivision.pack(side =LEFT)
  69.  
  70. #BOTTHREE ROW OF NUMBERS AND FUNCTIONS
  71. def botthree_row():
  72. frame2 = Frame(root)
  73. frame2.pack(side = TOP)
  74.  
  75. buttonfour= Button(frame2,padx= 15, pady= 15, bd=8, text= "4", fg="green", bg="red", command= lambda:buttonClick(4))
  76. buttonfour.pack(side =LEFT)
  77. buttonfive= Button(frame2,padx= 15, pady= 15, bd=8, text= "5", fg="green", bg="red", command= lambda:buttonClick(5))
  78. buttonfive.pack(side =LEFT)
  79. buttonsix= Button(frame2,padx= 15, pady= 15, bd=8, text= "6", fg="green", bg="red", command= lambda:buttonClick(6))
  80. buttonsix.pack(side =LEFT)
  81. buttonopenbracket= Button(frame2, padx= 15,pady= 15, bd=8, text= "(", fg="green", bg="red", command= lambda:buttonClick("("))
  82. buttonopenbracket.pack(side =LEFT)
  83. buttonmultiply= Button(frame2, padx= 15, pady= 15, bd=8, text= "*", fg="green", bg="red", command= lambda:buttonClick("*"))
  84. buttonmultiply.pack(side =LEFT)
  85.  
  86. #BOTFOUR OF NUMBERS AND FUNCTIONS
  87. def botfour_row():
  88. frame1 = Frame(root)
  89. frame1.pack(side = TOP)
  90.  
  91. buttonseven= Button(frame1,padx= 15, pady= 15, bd=8, text= "7", fg="green", bg="red", command= lambda:buttonClick(7))
  92. buttonseven.pack(side =LEFT)
  93. buttoneight= Button(frame1,padx= 15, pady= 15, bd=8, text= "8", fg="green", bg="red", command= lambda:buttonClick(8))
  94. buttoneight.pack(side =LEFT)
  95. buttonnine= Button(frame1,padx= 15, pady= 15, bd=8, text="9", fg= "green", bg="red", command= lambda:buttonClick(9))
  96. buttonnine.pack(side =LEFT)
  97. buttonclear= Button(frame1,padx=35, pady= 15, bd=8, text= "CLR", fg="green", bg="red2", command= lambda:clear())
  98. buttonclear.pack(side =LEFT)
  99.  
  100. display()
  101. bot_row()
  102. bottwo_row()
  103. botthree_row()
  104. botfour_row()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement