Advertisement
Guest User

Untitled

a guest
Dec 1st, 2018
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.10 KB | None | 0 0
  1. from tkinter import *
  2. import math
  3.  
  4. root = Tk()
  5. root.title('CALC+')
  6. root.geometry('300x200')
  7. root.resizable(width=False, height=False)
  8.  
  9. num_list = []
  10. last_num_list = [0]
  11.  
  12. def int_or_float(n):
  13. return int(n) == float(n)
  14.  
  15. def main_func():
  16. if num_list[1] == '+':
  17. num_list.append(input_ent.get())
  18. res = float(num_list[0]) + float(num_list[2])
  19. if int_or_float(res) == True:
  20. res_lb.config(text=int(res))
  21. elif int_or_float(res) == False:
  22. res_lb.config(text=float(res))
  23. last_num_list[0] = res
  24. input_ent.delete(0, 'end')
  25. num_list.clear()
  26. elif num_list[1] == '-':
  27. num_list.append(input_ent.get())
  28. res = float(num_list[0]) - float(num_list[2])
  29. if int_or_float(res) == True:
  30. res_lb.config(text=int(res))
  31. elif int_or_float(res) == False:
  32. res_lb.config(text=float(res))
  33. last_num_list[0] = res
  34. input_ent.delete(0, 'end')
  35. num_list.clear()
  36. elif num_list[1] == '*':
  37. num_list.append(input_ent.get())
  38. res = float(num_list[0]) * float(num_list[2])
  39. if int_or_float(res) == True:
  40. res_lb.config(text=int(res))
  41. elif int_or_float(res) == False:
  42. res_lb.config(text=float(res))
  43. last_num_list[0] = res
  44. input_ent.delete(0, 'end')
  45. num_list.clear()
  46. elif num_list[1] == '/':
  47. num_list.append(input_ent.get())
  48. res = float(num_list[0]) / float(num_list[2])
  49. if int_or_float(res) == True:
  50. res_lb.config(text=int(res))
  51. elif int_or_float(res) == False:
  52. res_lb.config(text=float(res))
  53. last_num_list[0] = res
  54. input_ent.delete(0, 'end')
  55. num_list.clear()
  56. elif num_list[1] == '%':
  57. num_list.append(input_ent.get())
  58. res = (float(num_list[0]) / 100) * float(num_list[2])
  59. if int_or_float(res) == True:
  60. res_lb.config(text=int(res))
  61. elif int_or_float(res) == False:
  62. res_lb.config(text=float(res))
  63. last_num_list[0] = res
  64. input_ent.delete(0, 'end')
  65. num_list.clear()
  66. elif num_list[1] == '**':
  67. num_list.append(input_ent.get())
  68. res = float(num_list[0]) ** float(num_list[2])
  69. if int_or_float(res) == True:
  70. res_lb.config(text=int(res))
  71. elif int_or_float(res) == False:
  72. res_lb.config(text=float(res))
  73. last_num_list[0] = res
  74. input_ent.delete(0, 'end')
  75. num_list.clear()
  76.  
  77. def add_list_plus():
  78. num_list.append(input_ent.get())
  79. num_list.append('+')
  80. input_ent.delete(0, 'end')
  81.  
  82. def add_list_minus():
  83. num_list.append(input_ent.get())
  84. num_list.append('-')
  85. input_ent.delete(0, 'end')
  86.  
  87. def add_list_umn():
  88. num_list.append(input_ent.get())
  89. num_list.append('*')
  90. input_ent.delete(0, 'end')
  91.  
  92. def add_list_del():
  93. num_list.append(input_ent.get())
  94. num_list.append('/')
  95. input_ent.delete(0, 'end')
  96.  
  97. def perc_num():
  98. num_list.append(input_ent.get())
  99. num_list.append('%')
  100. input_ent.delete(0, 'end')
  101.  
  102. def koren():
  103. res = math.sqrt(int(input_ent.get()))
  104. input_ent.delete(0, 'end')
  105. if int_or_float(res) == True:
  106. res_lb.config(text=int(res))
  107. elif int_or_float(res) == False:
  108. res_lb.config(text=float(res))
  109. last_num_list[0] = res
  110. num_list.clear()
  111.  
  112. def stepen():
  113. num_list.append(input_ent.get())
  114. num_list.append('**')
  115. input_ent.delete(0, 'end')
  116.  
  117. def last_num():
  118. if int_or_float(last_num_list[0]) == True:
  119. input_ent.insert(0, int(last_num_list[0]))
  120. elif int_or_float(last_num_list[0]) == False:
  121. print(last_num_list[0])
  122. input_ent.insert(0, float(last_num_list[0]))
  123.  
  124.  
  125.  
  126. wtm = Label(root, text='PRH.st 2018 (тестовая версия) V 0.2')
  127. input_ent = Entry(root)
  128. res_text_lb = Label(root, text='РЕЗУЛЬТАТ: ')
  129. res_lb = Label(root, text='0', width=0, height=0)
  130. last_num_but = Button(root, text='<<', width=0, height=1, command=last_num)
  131. plus_but = Button(root, text='+', width=12, height=2, command=add_list_plus)
  132. minus_but = Button(root, text='-', width=12, height=2, command=add_list_minus)
  133. umn_but = Button(root, text='*', width=12, height=2, command=add_list_umn)
  134. del_but = Button(root, text='/', width=12, height=2, command=add_list_del)
  135. res_but = Button(root, text='=', width=26, height=3, command=main_func)
  136. grey_canvas = Canvas(root, width=80, height=157, bg='Silver')
  137. perc_but = Button(root, text='%', width=8, height=2, command=perc_num)
  138. kor_but = Button(root, text='√', width=8, height=2, command=koren)
  139. stepen_but = Button(root, text='x²', width=8, height=2, command=stepen)
  140.  
  141. input_ent.place(x=10, y=10)
  142. res_text_lb.place(x=170, y=10)
  143. res_lb.place(x=240, y=10)
  144. last_num_but.place(x=140, y=5)
  145. plus_but.place(x=10, y=35)
  146. minus_but.place(x=108, y=35)
  147. umn_but.place(x=10, y=77)
  148. del_but.place(x=108, y=77)
  149. res_but.place(x=10, y=120)
  150. wtm.place(x=10, y=175)
  151. grey_canvas.place(x=210, y=33)
  152. perc_but.place(x=220, y=43)
  153. kor_but.place(x=220, y=93)
  154. stepen_but.place(x=220, y=143)
  155.  
  156. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement