-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
47 lines (34 loc) · 1.43 KB
/
main.py
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
import sys
from PyQt6.QtWidgets import QApplication, QMainWindow, QTextEdit, QLineEdit, QPushButton
from backend import ChatBot
import threading
class ChatbotWindow(QMainWindow):
def __init__(self):
super().__init__()
self.chatbot = ChatBot()
self.setMinimumSize(700, 500)
# Add chat area widget
self.chat_area = QTextEdit(self)
self.chat_area.setGeometry(10, 10, 480, 320)
self.chat_area.setReadOnly(True)
# Add the input field widget
self.input_field = QLineEdit(self)
self.input_field.setGeometry(10, 340, 480, 40)
self.input_field.returnPressed.connect(self.send_message)
# Add the button
self.button = QPushButton("Send", self)
self.button.setGeometry(500, 340, 100, 40)
self.button.clicked.connect(self.send_message)
self.show()
def send_message(self):
user_input = self.input_field.text().strip()
self.chat_area.append(f"<p style='color:#333333'>Me: {user_input} </p>")
self.input_field.clear()
thread = threading.Thread(target=self.get_bot_response, args=(user_input,))
thread.start()
def get_bot_response(self, user_input):
response = self.chatbot.get_response(user_input)
self.chat_area.append(f"<p style='color:#333333; background-color:#E9E9E9'>Bot: {response}</p>")
app = QApplication(sys.argv)
main_window = ChatbotWindow()
sys.exit(app.exec())