Advertisement
snowden_web

Untitled

Nov 29th, 2019
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.51 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. from tkinter import *
  3.  
  4. root = Tk()
  5. root.geometry("205x340")
  6. solution = None
  7. screen = Label(root, text = "0", font = "EngraversMT 12")
  8. screen.pack()
  9. def print_zero(event):
  10.     if screen["text"] != "0":
  11.         screen["text"] += "0"    
  12. def print_one(event):
  13.     if screen["text"] == "0":
  14.         screen["text"] = "1"
  15.     else:
  16.         screen["text"] += "1"
  17. def print_two(event):
  18.     if screen["text"] == "0":
  19.         screen["text"] = "2"
  20.     else:
  21.         screen["text"] += "2"
  22. def print_three(event):
  23.     if screen["text"] == "0":
  24.         screen["text"] = "3"
  25.     else:
  26.         screen["text"] += "3"
  27. def print_four(event):
  28.     if screen["text"] == "0":
  29.         screen["text"] = "4"
  30.     else:
  31.         screen["text"] += "4"
  32. def print_five(event):
  33.     if screen["text"] == "0":
  34.         screen["text"] = "5"
  35.     else:
  36.         screen["text"] += "5"
  37. def print_six(event):
  38.     if screen["text"] == "0":
  39.         screen["text"] = "6"
  40.     else:
  41.         screen["text"] += "6"
  42. def print_seven(event):
  43.     if screen["text"] == "0":
  44.         screen["text"] = "7"
  45.     else:
  46.         screen["text"] += "7"
  47. def print_eight(event):
  48.     if screen["text"] == "0":
  49.         screen["text"] = "8"
  50.     else:
  51.         screen["text"] += "8"
  52. def print_nine(event):
  53.     if screen["text"] == "0":
  54.         screen["text"] = "9"
  55.     else:
  56.         screen["text"] += "9"
  57. def _enter(event):
  58.     solve = screen["text"].split( )
  59.     if len(solve) == 1:
  60.         pass
  61.     elif solve[1] == "/":
  62.         screen["text"] = str(int(solve[0]) // int(solve[2]))
  63.     elif solve[1] == "*":
  64.         screen["text"] = str(int(solve[0]) * int(solve[2]))
  65.     elif solve[1] == "-":
  66.         screen["text"] = str(int(solve[0]) - int(solve[2]))  
  67.     elif solve[1] == "+":
  68.         screen["text"] = str(int(solve[0]) + int(solve[2]))      
  69. def division(event):
  70.     _enter(event)
  71.     screen["text"] += " / "
  72. def multiply(event):
  73.     _enter(event)
  74.     screen["text"] += " * "
  75. def _minus(event):
  76.     _enter(event)
  77.     screen["text"] += " - "
  78. def _plus(event):
  79.     _enter(event)
  80.     screen["text"] += " + "
  81. def _backspace(event):
  82.     if len(screen["text"]) > 1:
  83.         screen["text"] = screen["text"][:-1:1]
  84.     else:
  85.         screen["text"] = "0"
  86. def _sqr(event):
  87.     screen["text"] = str(int(screen["text"]) ** 2)
  88. def _clear(event):
  89.     screen["text"] = "0"
  90.  
  91. div = Button(root, text = "/", width = 5, height = 3)
  92. mul = Button(root, text = "*", width = 5, height = 3)
  93. backspace = Button(root, text = "<--", width = 5, height = 3)
  94. minus = Button(root, text = "-", width = 5, height = 3)
  95. plus = Button(root, text = "+", width = 5, height = 7)
  96. enter = Button(root, text = "=", width = 5, height = 3)
  97. seven = Button(root, text = "7", width = 5, height = 3)
  98. eight = Button(root, text = "8", width = 5, height = 3)
  99. nine = Button(root, text = "9", width = 5, height = 3)
  100. four = Button(root, text = "4", width = 5, height = 3)
  101. five = Button(root, text = "5", width = 5, height = 3)
  102. six = Button(root, text = "6", width = 5, height = 3)
  103. one = Button(root, text = "1", width = 5, height = 3)
  104. two = Button(root, text = "2", width = 5, height = 3)
  105. three = Button(root, text = "3", width = 5, height = 3)
  106. zero = Button(root, text = "0", width = 12, height = 3)
  107. sqr = Button(root, text = "x^2", width = 5, height = 3)
  108. clear = Button(root, text = "C", width = 5, height = 3)
  109. zero.bind("<Button-1>", print_zero)
  110. zero.place(x = 5, y = 280)
  111. one.bind("<Button-1>", print_one)
  112. one.place(x = 5, y = 220)
  113. two.bind("<Button-1>", print_two)
  114. two.place(x = 55, y = 220)
  115. three.bind("<Button-1>", print_three)
  116. three.place(x = 105, y = 220)
  117. four.bind("<Button-1>", print_four)
  118. four.place(x = 5, y = 160)
  119. five.bind("<Button-1>", print_five)
  120. five.place(x = 55, y = 160)
  121. six.bind("<Button-1>", print_six)
  122. six.place(x = 105, y = 160)
  123. seven.bind("<Button-1>", print_seven)
  124. seven.place(x = 5, y = 100)
  125. eight.bind("<Button-1>", print_eight)
  126. eight.place(x = 55, y = 100)
  127. nine.bind("<Button-1>", print_nine)
  128. nine.place(x = 105, y = 100)
  129. sqr.bind("<Button-1>", _sqr)
  130. sqr.place(x = 105, y = 40)
  131. clear.bind("<Button-1>", _clear)
  132. clear.place(x = 105, y = 280)
  133. backspace.bind("<Button-1>", _backspace)
  134. backspace.place(x = 155, y = 40)
  135. div.bind("<Button-1>", division)
  136. div.place(x = 5, y = 40)
  137. mul.bind("<Button-1>", multiply)
  138. mul.place(x = 55, y = 40)
  139. minus.bind("<Button-1>", _minus)
  140. minus.place(x = 155, y = 100)
  141. plus.bind("<Button-1>", _plus)
  142. plus.place(x = 155, y = 160)
  143. enter.bind("<Button-1>", _enter)
  144. enter.place(x = 155, y = 280)
  145. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement