0
0 Комментариев

Написал (точнее переписал с сайта) калькулятор, все правильно, но что бы я не делал, выдает ошибки, хоть и все написано правильно. Код приложил ниже.

Python 3.7.3

Windows 10 x64

Редактор Sublime text 3

Библиотеки tkinter, math.

При запуске с консоли, пишет: python calc.py
Traceback (most recent call last):
File «calc.py», line 7, in <module>
root.tittle(«Calculator»)
File «C:\Users\****\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py», line 2101, in __getattr__
return getattr(self.tk, attr)
AttributeError: ‘_tkinter.tkapp’ object has no attribute ‘tittle’

При запуске как exe (pyinstaller): Traceback (most recent call last):
File «calc.py», line 7, in <module>
File «tkinter\__init__.py», line 2101, in __getattr__
AttributeError: ‘_tkinter.tkapp’ object has no attribute ‘tittle’
[11160] Failed to execute script calc

from tkinter import *
from tkinter import messagebox
from tkinter import ttk
import math
import sys
root = Tk()
root.tittle("Calculator")
bttn_list = [
"7", "8", "9", "+", "*", 
"4", "5", "6", "-", "/",
"1", "2", "3",  "=", "xⁿ",
"0", ".", "±",  "C",
"Exit", "π", "sin", "cos",
"(", ")","n!","√2", ]
r = 1
c = 0
for i in bttn_list:
 rel = ""
 cmd=lambda x=i: calc(x)
 ttk.Button(root, text=i, command = cmd, width = 10).grid(row=r, column = c)
 c += 1
 if c > 4:
  c = 0
  r += 1
calc_entry = Entry(root, width = 33)
calc_entry.grid(row=0, column=0, columnspan=5)
#логика калькулятора
def calc(key):
 global memory
 if key == "=":
#исключение написания слов
  str1= "-+0123456789.*/)("
  if calc_entry.get()[0] not in str1:
   calc_entry.insert(END, "First symbol is not number!")
   messagebox.showerror("Error!", "You did not enter the number!")
#исчисления
  try:
   result = eval(calc_entry.get())
   calc_entry.insert(END, "=" + str(results))
  except:
   calc_entry.insert (END, "Error!")
   messagebox.showerror("Error!", "Check the correctness of data")
#очищение поля ввода
 elif key == "C":
  calc_entry.delete(0, END)
 elif key == "±":
  if "=" in calc_entry.get():
   calc_entry.delete(0, END)
  try:
   if calc_entry.get() [0] == "-":
    calc_entry.delete(0)
   else:
    calc_entry.insert(0, "-")
  except IndexError:
   pass
 elif key == "π":
  calc_entry.insert(END, math.pi)
 elif key == "Exit":
  root.after(1,root.destroy)
  sys.exit
 elif key == "xⁿ":
  calc_entry.insert(END, "**")
 elif key == "sin":
   calc_entry.insert(END, "=" + str(math.sin(int(calc_entry.get()))))
 elif key == "cos":
   calc_entry.insert(END, "=" + str(math.cos(int(calc_entry.get()))))
 elif key == "(":
   calc_entry.insert(END, "(")
 elif key == ")":
   calc_entry.insert(END, ")")
 elif key == "n!":
   calc_entry.insert(END, "=" + str(math.factorial(int(calc_entry.get()))))
 elif key == "√2":
   calc_entry.insert(END, "=" + str(math.sqrt(int(calc_entry.get()))))
 else:
   if "=" in calc_entry.get():
    calc_entry.delete(0, END)
   calc_entry.insert(END, key)
root.mainloop()


Добавить комментарий