# калькулятор

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98``` ```#-*- coding:cp1251 -*- from Tkinter import * import math expression = result = '' def press(symbol): global expression expression += str(symbol) lblexpression.configure(text=expression) def sqrt(): global expression, result result = str(math.sqrt(eval(expression))) lblresult.configure(text=result) def c(): global expression, result expression = result = '' lblexpression.configure(text='') lblresult.configure(text='') def equal(): global result, expression result = str(eval(expression)) lblresult.configure(text=result) def applyskin(skin): global skincolor if skin == 'red': skincolor = '#ff3434' # GUI skincolor = '#ffb75f' root = Tk() root.title("pyCalc Orange/Black") root.resizable(0, 0) menu = Menu(root) root.config(menu=menu) filemenu = Menu(menu) menu.add_cascade(label=u"Файл", menu=filemenu) filemenu.add_command(label=u"Очистить", command=c) filemenu.add_separator() filemenu.add_command(label=u"Выход", command=exit) #skinmenu = Menu(menu) #menu.add_cascade(label=u"Шкурка", menu=skinmenu) #skinmenu.add_command(label=u"Красная", command=c) frame = Frame(root, background=skincolor) frame.pack() # лейблы lblexpression = Label(frame, text='', width=20, background='red', font=("Arial", 20, "bold")) lbltext = Label(frame, text=u'результат:', width=10, background=skincolor, font=("Arial", 15, "bold")) lblresult = Label(frame, text='', width=19, background=skincolor, font=("Arial", 12, "bold")) lblexpression.grid(row=0, column=0, columnspan=5) lbltext.grid(row=1, column=0, columnspan=2) lblresult.grid(row=1, column=2, columnspan=3) # кнопки btns = [] input_expression = range(10) + ['+', '*', '-', '/', '.'] for symbol in input_expression + ['=', 'off', 'sqrt', 'C']: btns.append(Button(frame, text=str(symbol), width=3, fg='white', bg='black', font=('Comic Sans MS', 20, "bold"), command= (lambda symbol: lambda: press(symbol))(symbol))) btns[0].grid(row=5, column=0, padx=4, pady=4) btns[1].grid(row=4, column=0, pady=4) btns[2].grid(row=4, column=1) btns[3].grid(row=4, column=2) btns[4].grid(row=3, column=0, pady=4) btns[5].grid(row=3, column=1) btns[6].grid(row=3, column=2) btns[7].grid(row=2, column=0, pady=4) btns[8].grid(row=2, column=1) btns[9].grid(row=2, column=2) btns[10].grid(row=4, column=3, padx=4, rowspan=2) # сложение btns[11].grid(row=5, column=4, padx=4) # умножение btns[12].grid(row=3, column=3) # вычитание btns[13].grid(row=4, column=4) # деление btns[14].grid(row=5, column=1, padx=4) # точка btns[15].grid(row=5, column=2, padx=4) # равно btns[16].grid(row=2, column=4) # выход btns[17].grid(row=3, column=4) # извл. кв. корня btns[18].grid(row=2, column=3) # очистка btns[10].configure(height=3) btns[15].configure(command=equal) btns[16].configure(command=exit, bg='red') btns[17].configure(command=sqrt) btns[18].configure(command=c) root.mainloop() ```