Advertisement
Guest User

hfhj

a guest
Sep 22nd, 2014
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.14 KB | None | 0 0
  1. from Tkinter import *
  2.  
  3.  
  4. def but1():
  5. bt1 = entry2.get()
  6. display2.set (str(bt1) + "1")
  7. def but2():
  8. bt1 = entry2.get()
  9. display2.set (str(bt1) + "2")
  10. def but3():
  11. bt1 = entry2.get()
  12. display2.set (str(bt1) + "3")
  13. def but4():
  14. bt1 = entry2.get()
  15. display2.set (str(bt1) + "4")
  16. def but5():
  17. bt1 = entry2.get()
  18. display2.set (str(bt1) + "5")
  19. def but6():
  20. bt1 = entry2.get()
  21. display2.set (str(bt1) + "6")
  22. def but7():
  23. bt1 = entry2.get()
  24. display2.set (str(bt1) + "7")
  25. def but8():
  26. bt1 = entry2.get()
  27. display2.set (str(bt1) + "8")
  28. def but9():
  29. bt1 = entry2.get()
  30. display2.set (str(bt1) + "9")
  31. def but0():
  32. bt1 = entry2.get()
  33. display2.set (str(bt1) + "0")
  34. def but11():
  35. bt1 = entry2.get()
  36. display2.set (str(bt1) + " + ")
  37. def but12():
  38. bt1 = entry2.get()
  39. display2.set (str(bt1) + " - ")
  40. def but13():
  41. bt1 = entry2.get()
  42. display2.set (str(bt1) + " * ")
  43. def but14():
  44. bt1 = entry2.get()
  45. display2.set (str(bt1) + " / ")
  46. def but15():
  47. bt1 = entry2.get()
  48. display2.set (str(bt1) + " . ")
  49. def but16():
  50. bt1 = entry2.get()
  51. display2.set (str(bt1) + "-")
  52.  
  53.  
  54. def operation():
  55. eq1 = str(entry2.get())
  56. a, op, b = eq1.split()
  57. if op == "+":
  58. display2.set(float(a) + float(b))
  59. elif op =="-":
  60. display2.set (float(a) - float(b))
  61. elif op =="*":
  62. display2.set (float(a) * float(b))
  63. elif op =="/":
  64. display2.set (float(a) / float(b))
  65.  
  66.  
  67.  
  68.  
  69.  
  70. def clear():
  71. display2.set("")
  72.  
  73.  
  74. # main
  75. root = Tk()
  76. root.title("Calculator by Ash")
  77. root.geometry("320x670")
  78.  
  79. gap1= Frame(root, height=20, width=50)
  80. gap1.pack()
  81.  
  82. global display2
  83. display2 = StringVar(None)
  84. entry2 = Entry(root, justify = 'center', textvariable=display2, width=30)
  85. entry2.pack()
  86.  
  87. gap2= Frame(root, height=20, width=50)
  88. gap2.pack()
  89.  
  90. app = Frame(root)
  91. app.grid()
  92.  
  93. frame1= Frame(root, width=20)
  94. frame1.pack()
  95.  
  96. button1 = Button(frame1, text = "1", height=7, width=7, command=but1)
  97. button1.pack(side = LEFT )
  98.  
  99. button2 = Button(frame1, text = "2", height=7, width=7, command=but2)
  100. button2.pack( side = LEFT )
  101.  
  102. button3 = Button(frame1, text = "3", height=7, width=7, command=but3)
  103. button3.pack( side = LEFT )
  104.  
  105. button4 = Button(frame1, text = "*", height=7, width=7, command=but13)
  106. button4.pack( side = LEFT )
  107.  
  108. frame2= Frame(root, width=20)
  109. frame2.pack()
  110.  
  111. button5 = Button(frame2, text = "4", height=7, width=7, command=but4)
  112. button5.pack(side = LEFT )
  113.  
  114. button6 = Button(frame2, text = "5", height=7, width=7, command=but5)
  115. button6.pack( side = LEFT )
  116.  
  117. button7 = Button(frame2, text = "6", height=7, width=7, command=but6)
  118. button7.pack( side = LEFT )
  119.  
  120. button8 = Button(frame2, text = "+", height=7, width=7, command=but11)
  121. button8.pack( side = LEFT )
  122.  
  123. frame3= Frame(root, width=20)
  124. frame3.pack()
  125.  
  126. button9 = Button(frame3, text = "7", height=7, width=7, command=but7)
  127. button9.pack(side = LEFT )
  128.  
  129. button10 = Button(frame3, text = "8", height=7, width=7, command=but8)
  130. button10.pack( side = LEFT )
  131.  
  132. button11 = Button(frame3, text = "9", height=7, width=7, command=but9)
  133. button11.pack( side = LEFT )
  134.  
  135. button12 = Button(frame3, text = "-", height=7, width=7, command=but12)
  136. button12.pack(side = LEFT )
  137.  
  138. frame4= Frame(root, width=20)
  139. frame4.pack()
  140.  
  141. button13 = Button(frame4, text = "0", height=7, width=7, command=but0)
  142. button13.pack(side = LEFT )
  143.  
  144. button14 = Button(frame4, text = "(C)", height=7, width=7,command=clear)
  145. button14.pack(side = LEFT )
  146.  
  147. button15 = Button(frame4, text = "(.)", height=7, width=7, command=but15)
  148. button15.pack( side = LEFT )
  149.  
  150. button16 = Button(frame4, text = "/", height=7, width=7, command=but14)
  151. button16.pack( side = LEFT )
  152.  
  153. frame5= Frame(root, width=20)
  154. frame5.pack()
  155.  
  156. button17 = Button(frame5, text = "=", height=7, width=7, command=operation)
  157. button17.pack( side = LEFT )
  158.  
  159. button18 = Button(frame5, text = "(-)", height=7, width=7, command=but16)
  160. button18.pack( side = LEFT )
  161.  
  162.  
  163.  
  164. #label = Label(app, text = "rawr")
  165. #label.grid()
  166.  
  167. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement