Проблема всплывающего окна для интерфейса в PythonPython

Программы на Python
Anonymous
Проблема всплывающего окна для интерфейса в Python

Сообщение Anonymous »

Проблема всплывающего окна для интерфейса в Python
ВОТ КОД -

Код: Выделить всё

from tkinter import *

from chat import get_response, bot_name

import pyttsx3

engine=pyttsx3.init()

BG_GRAY = "#d4930b"

BG_COLOR = "#f2ece0"

TEXT_COLOR = "#000000"

FONT = "Helvetica 12"

FONT_BOLD = "Helvetica 11 bold"

class ChatApplication():

def _init_(self):

self.window = Tk()

self._setup_main_window()

def run(self):

self.window.mainloop()

def _setup_main_window(self):

self.window.title("ChatBot")

self.window.resizable(width=False, height=False)

self.window.configure(width=750, height=600, bg=BG_GRAY)

# head label

head_label = Label(self.window, bg=BG_COLOR, fg=TEXT_COLOR,

text="IIUC Admission Helpdesk", font=FONT_BOLD,

pady=10)

head_label.place(relwidth=1)

# tiny divider

line = Label(self.window, width=450, bg=BG_GRAY)

line.place(relwidth=1, rely=0.07, relheight=0.012)

# text widget

self.text_widget = Text(self.window, width=20, height=2, bg=BG_COLOR, fg=TEXT_COLOR, font=FONT, padx=5, pady=5)

self.text_widget.place(relheight=0.745, relwidth=1, rely=0.08)

self.text_widget.configure(cursor="arrow", state=DISABLED)

# scroll bar

scrollbar = Scrollbar(self.text_widget)

scrollbar.place(relheight=1, relx=0.974)

scrollbar.configure(command=self.text_widget.yview)

# bottom label

bottom_label = Label(self.window, bg=BG_GRAY, height=80)

bottom_label.place(relwidth=1, rely=0.825)

# message entry box

self.msg_entry = Entry(bottom_label, bg="#dedfde", fg=TEXT_COLOR,

font=FONT)

self.msg_entry.place(relwidth=0.74, relheight=0.06, rely=0.008, relx=0.011)

self.msg_entry.focus()

self.msg_entry.bind("", self._on_enter_pressed)

# send button

send_button = Button(bottom_label, text="Send", font=FONT_BOLD, width=20, bg=BG_GRAY, command=lambda:

self._on_enter_pressed(None))

send_button.place(relx=0.77, rely=0.008, relheight=0.06, relwidth=0.22)

def _on_enter_pressed(self, event):

msg = self.msg_entry.get()

self._insert_message(msg, "You")

def _insert_message(self, msg, sender):

if not msg:

# return

self.msg_entry.delete(0, END)

msg1 = f"{sender}: {msg}\n\n"

self.text_widget.configure(state=NORMAL)

self.text_widget.insert(END, msg1)

self.text_widget.configure(state=DISABLED)

msg2 = f"{bot_name}: {get_response(msg)}\n\n"

self.text_widget.configure(state=NORMAL)

self.text_widget.insert(END, msg2)

self.text_widget.configure(state=DISABLED)

self.text_widget.see(END)

#speak(msg2)

def speak(Response):

engine.say(Response)

engine.runAndWait()

app = ChatApplication()

app.run()

Я ожидал, что появится всплывающее окно, чтобы показать мне интерфейс, но вместо этого оно показывает ошибку - Traceback (последний последний вызов): Файл "C:\AI Projects\ChatBot\app.py ", строка 78, в app.run() Файл "C:\AI Projects\ChatBot\app.py", строка 16, в run self.window.mainloop() ^^^^^^^^^^^ AttributeError : объект ChatApplication не имеет атрибута window "C:\AI Projects\ChatBot\app.py", строка 16, при запуске self.window.mainloop() ^^^^^^^^^^^ AttributeError: Объект ChatApplication не имеет атрибута window

Подробнее здесь: https://stackoverflow.com/questions/784 ... -in-python

Вернуться в «Python»