الكود :
from turtle import Turtle ,Screen
from math import sqrt
from time import sleep
window = Screen ()
window.setup (690,820)
window.title ('calculator')
window.tracer (0)
window.bgpic ('calculator.png')
sam = Turtle ('circle')
sam.hideturtle ()
sam.penup ()
sam.goto (-290,290)
y_n = False
numbers = ""
def clear ():
sam.clear ()
sam .write ("".join(numbers),font = ('Arial',15,'normal'))
window.update ()
def press_on (presses):
global numbers
numbers += presses
clear ()
def equal ():
global numbers
length = 0
new_numbers = ""
if numbers :
for number in numbers :
if length > 0:
length -= 1
continue
if number == '×':
new_numbers += '*'
elif number == '÷':
new_numbers += '/'
elif number == '^':
new_numbers += '**'
elif number == '√':
if numbers [-2] == '√':
new_numbers += 'error'
break
numb = ""
dis = False
for n in numbers [numbers.index(number)+1::]:
try:
numb += str ( int (n))
except:
if dis:
break
dis = True
length = len(numb)+1
numb = float (numb)
new_numbers += str (sqrt (numb))
else :
new_numbers += (number)
try:
numbers = str(eval(new_numbers))
except :
numbers = "error"
clear ()
def clicked ( x, y):
global sam
global numbers
global y_n
if numbers == 'error':
numbers = ""
clear ()
if -200 > x > -350 and 150 > y > 0:
press_on ('1')
elif -50 > x > -200 and 150 > y > 0:
press_on ('2')
elif 100 > x > -50 and 150 > y > 0:
press_on ('3')
elif -200 > x > -350 and 0 > y > -150:
press_on ('4')
elif -50 > x > -200 and 0 > y > -150:
press_on ('5')
elif 100 > x > -50 and 0 > y > -150:
press_on ('6')
elif -200 > x > -350 and -150 > y > -300:
press_on ('7')
elif -50 > x > -200 and -150 > y > -300:
press_on ('8')
elif 100 > x > -50 and -150 > y > -300:
press_on ('9')
elif -50 > x > -200 and -300 > y > -450:
press_on ('0')
elif -200 > x > -350 and -300 > y > -450:
press_on ('.')
elif 100 > x > -50 and -300 > y > -450:
if numbers :
if not y_n:
y_n = True
deleted = ''
if numbers [-1] == ' ':
for x in range (len(numbers)-3):
deleted += numbers [x]
else :
for x in range (len(numbers)-1):
deleted += numbers [x]
numbers = deleted
clear ()
else :
numbers = ""
clear ()
sleep (0.5)
y_n = False
elif 200 > x > 100 and 150 > y > 0:
press_on (' + ')
elif 300 > x > 200 and 150 > y > 0:
press_on (' - ')
elif 200 > x > 100 and 0 > y > -150:
press_on (' × ')
elif 300 > x > 200 and 0 > y > -150:
press_on (' ÷ ')
elif 200 > x > 100 and -150 > y > -300:
press_on (' ^ ')
elif 300 > x > 200 and -150 > y > -300:
press_on (' √ ')
elif 200 > x > 150 and -300 > y > -450:
press_on (')')
elif 150 > x > 100 and -300 > y > -450:
press_on ('(')
elif 300 > x > 200 and -300 > y > -450:
equal ()
window.onscreenclick (clicked)
window.mainloop ()
الصوره المستعمله :
صور للآله :