Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- import math
- root = Tk()
- root.title('CALC+')
- root.geometry('300x200')
- root.resizable(width=False, height=False)
- num_list = []
- last_num_list = [0]
- def int_or_float(n):
- return int(n) == float(n)
- def main_func():
- if num_list[1] == '+':
- num_list.append(input_ent.get())
- res = float(num_list[0]) + float(num_list[2])
- if int_or_float(res) == True:
- res_lb.config(text=int(res))
- elif int_or_float(res) == False:
- res_lb.config(text=float(res))
- last_num_list[0] = res
- input_ent.delete(0, 'end')
- num_list.clear()
- elif num_list[1] == '-':
- num_list.append(input_ent.get())
- res = float(num_list[0]) - float(num_list[2])
- if int_or_float(res) == True:
- res_lb.config(text=int(res))
- elif int_or_float(res) == False:
- res_lb.config(text=float(res))
- last_num_list[0] = res
- input_ent.delete(0, 'end')
- num_list.clear()
- elif num_list[1] == '*':
- num_list.append(input_ent.get())
- res = float(num_list[0]) * float(num_list[2])
- if int_or_float(res) == True:
- res_lb.config(text=int(res))
- elif int_or_float(res) == False:
- res_lb.config(text=float(res))
- last_num_list[0] = res
- input_ent.delete(0, 'end')
- num_list.clear()
- elif num_list[1] == '/':
- num_list.append(input_ent.get())
- res = float(num_list[0]) / float(num_list[2])
- if int_or_float(res) == True:
- res_lb.config(text=int(res))
- elif int_or_float(res) == False:
- res_lb.config(text=float(res))
- last_num_list[0] = res
- input_ent.delete(0, 'end')
- num_list.clear()
- elif num_list[1] == '%':
- num_list.append(input_ent.get())
- res = (float(num_list[0]) / 100) * float(num_list[2])
- if int_or_float(res) == True:
- res_lb.config(text=int(res))
- elif int_or_float(res) == False:
- res_lb.config(text=float(res))
- last_num_list[0] = res
- input_ent.delete(0, 'end')
- num_list.clear()
- elif num_list[1] == '**':
- num_list.append(input_ent.get())
- res = float(num_list[0]) ** float(num_list[2])
- if int_or_float(res) == True:
- res_lb.config(text=int(res))
- elif int_or_float(res) == False:
- res_lb.config(text=float(res))
- last_num_list[0] = res
- input_ent.delete(0, 'end')
- num_list.clear()
- def add_list_plus():
- num_list.append(input_ent.get())
- num_list.append('+')
- input_ent.delete(0, 'end')
- def add_list_minus():
- num_list.append(input_ent.get())
- num_list.append('-')
- input_ent.delete(0, 'end')
- def add_list_umn():
- num_list.append(input_ent.get())
- num_list.append('*')
- input_ent.delete(0, 'end')
- def add_list_del():
- num_list.append(input_ent.get())
- num_list.append('/')
- input_ent.delete(0, 'end')
- def perc_num():
- num_list.append(input_ent.get())
- num_list.append('%')
- input_ent.delete(0, 'end')
- def koren():
- res = math.sqrt(int(input_ent.get()))
- input_ent.delete(0, 'end')
- if int_or_float(res) == True:
- res_lb.config(text=int(res))
- elif int_or_float(res) == False:
- res_lb.config(text=float(res))
- last_num_list[0] = res
- num_list.clear()
- def stepen():
- num_list.append(input_ent.get())
- num_list.append('**')
- input_ent.delete(0, 'end')
- def last_num():
- if int_or_float(last_num_list[0]) == True:
- input_ent.insert(0, int(last_num_list[0]))
- elif int_or_float(last_num_list[0]) == False:
- print(last_num_list[0])
- input_ent.insert(0, float(last_num_list[0]))
- wtm = Label(root, text='PRH.st 2018 (тестовая версия) V 0.2')
- input_ent = Entry(root)
- res_text_lb = Label(root, text='РЕЗУЛЬТАТ: ')
- res_lb = Label(root, text='0', width=0, height=0)
- last_num_but = Button(root, text='<<', width=0, height=1, command=last_num)
- plus_but = Button(root, text='+', width=12, height=2, command=add_list_plus)
- minus_but = Button(root, text='-', width=12, height=2, command=add_list_minus)
- umn_but = Button(root, text='*', width=12, height=2, command=add_list_umn)
- del_but = Button(root, text='/', width=12, height=2, command=add_list_del)
- res_but = Button(root, text='=', width=26, height=3, command=main_func)
- grey_canvas = Canvas(root, width=80, height=157, bg='Silver')
- perc_but = Button(root, text='%', width=8, height=2, command=perc_num)
- kor_but = Button(root, text='√', width=8, height=2, command=koren)
- stepen_but = Button(root, text='x²', width=8, height=2, command=stepen)
- input_ent.place(x=10, y=10)
- res_text_lb.place(x=170, y=10)
- res_lb.place(x=240, y=10)
- last_num_but.place(x=140, y=5)
- plus_but.place(x=10, y=35)
- minus_but.place(x=108, y=35)
- umn_but.place(x=10, y=77)
- del_but.place(x=108, y=77)
- res_but.place(x=10, y=120)
- wtm.place(x=10, y=175)
- grey_canvas.place(x=210, y=33)
- perc_but.place(x=220, y=43)
- kor_but.place(x=220, y=93)
- stepen_but.place(x=220, y=143)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement