@foldgame

Решение ошибки has no attribute 'run'?

Здравствуйте! Написал простенький блокнот, но при запуске выдаёт ошибку:
File "prostoNote.py", line 219, in <module>
    notepad.run()
AttributeError: 'Notepad' object has no attribute 'run')


prostoNote v.1.0
import tkinter
import os
from tkinter import *
from tkinter.messagebox import *
from tkinter.filedialog import *

class Notepad:

	__root = Tk()

	# размеры окна
	
	__thisWidth = 600
	
	__thisHeight = 300
	
	__thisTextArea = Text(__root)

	# добавление меню

	__thisMenuBar = Menu(__root)

	__thisFileMenu = Menu(__thisMenuBar, tearoff = 0)

	__thisEditMenu = Menu(__thisMenuBar, tearoff = 0)

	__thisHelpMenu = Menu(__thisMenuBar, tearoff = 0)

	# полоса прокрутки

	__thisScrollBar = Scrollbar(__thisTextArea)

	__file = None

	def  __init__(self, **kwargs):

		# установить иконку

		try:
			self.__root.wm_iconbitmap("Notepad.ico")

		except:
			pass

		# установить размер окна по умолчанию (600х300)

		try:
			self.__thisWidth = kwargs['width']

		except KeyError:
			pass

		# заголовок окна

		self.__root.title("Untitled - Notepad")

		# центрировать окно

		screenWidht = self.__root.winfo_screenwidth()

		screenHeight = self.__root.winfo_screenheight()

		# для левой

		left = (screenWidht / 2) - (self.__thisWidth / 2)

		# для правой

		top = (screenHeight / 2) - (self.__thisHeight / 2)

		# для верхней и нижней

		self.__root.geometry('%dx%d+%d+%d' % (self.__thisWidth, self.__thisHeight, left, top))

		# чтобы текстовую область автоматически изменяемой

		self.__root.grid_rowconfigure(0, weight = 1)

		self.__root.grid_columnconfigure(0, weight = 1)

		# добавить элементы управления (виджет)

		self.__thisTextArea.grid(sticky = N + E + S + W)

		# открыть новый файл

		self.__thisFileMenu.add_command(label = "Создать файл", command = self.__newFile)

		# открыть существующий файл

		self.__thisFileMenu.add_command(label = "Открыть", command = self.__openFile)

		# сохранить файл

		self.__thisFileMenu.add_command(label = "Сохранить", command = self.__saveFile)

		# создать строку в диалоге

		self.__thisFileMenu.add_separator()

		self.__thisFileMenu.add_command(label = "Выйти", command = self.__quitApplication)

		self.__thisMenuBar.add_cascade(label = "Файл", menu = self.__thisFileMenu)

		# функции вырезать, копировать, вставить

		self.__thisEditMenu.add_command(label = "Вырезать", command = self.__cut)

		self.__thisEditMenu.add_command(label = "Копировать", command = self.__copy)

		self.__thisEditMenu.add_command(label = "Вставить", command = self.__paste)

		# меню редактирования текста

		self.__thisEditMenu.add_cascade(label = "Правка", menu = self.__thisEditMenu)

		# меню-описание

		self.__thisHelpMenu.add_command(label = "О программе", command = self.__showAbout)

		self.__thisMenuBar.add_cascade(label = "Помощь", menu = self.__thisHelpMenu)

		self.__root.config(menu = self.__thisMenuBar)

		self.__thisScrollBar.pack(side = RIGHT, fill = Y)

		# регулирование полосы прокрутки

		self.__thisScrollBar.config(command = self.__thisTextArea.yview)

		self.__thisTextArea.config(yscrollcommand = self.__thisScrollBar.set)

	def __quitApplication(self):

		self.__root.destroy()

	def __showAbout(self):

		showinfo("Блокнот", "Программа \"prostoNote\", версия 1.0. Разработчик: Dranov. Сайт: denis.dranov14.12@mail.ru.")

	def __openFile(self):

		self.__file = askopenfilename(defaultextension = ".txt", filetypes = [("All Files", "*.*"), ("Text Documents", "*.txt")])

		if self.__file == "":

			self.__file = None

		else:

			self.__root.title(os.path.basename(self.__file) + " - Блокнот")

			self.__thisTextArea.delete(1.0, END)

			file = open(self.__file, "r")

			self.__thisTextArea.insert(1.0, file.read())

			file.close()

	def __newFile(self):

		self.__root.title("Безымянный - Блокнот")

		self.__file = None

		self.__thisTextArea.delete(1.0, END)

	def __saveFile(self):

		if self.__file == None:

			self.__file = asksaveasfilename(initialfile = "Безымянный.txt", defaultextension = ".txt", filetypes = [("All Files", "*.*"), ("Text Documents", "*.txt")])

			if self.__file == "":

				self.__file = None

			else:

				file = open(self.__file, "w")

				file.write(self.__thisTextArea.get(1.0, END))

				file.close()

				self.__root.title(os.path.basename(self.__file) + " - Блокнот")

		else:

			file = open(self.__file, "w")

			file.write(self.__thisTextArea.get(1.0, END))

			file.close()

	def __cut(self):

		self.__thisTextArea.event_generate("Вырезать")

	def __copy(self):

		self.__thisTextArea.event_generate("Копировать")

	def __paste(self):

		self.__thisTextArea.event_generate("Вставить")

	def __run(self):

		self.__root.mainloop()


# запуск приложения

notepad = Notepad(width=600, height=300)
notepad.run()
  • Вопрос задан
  • 629 просмотров
Решения вопроса 1
@barolina
turn coffee into code
так у вас его и нет, должно наверно так быть
# def __run(self):
 def run(self):

    self.__root.mainloop()
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы