forked from seyitalikara/python_gui_example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui_x_002.py
More file actions
68 lines (53 loc) · 2.15 KB
/
gui_x_002.py
File metadata and controls
68 lines (53 loc) · 2.15 KB
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
import tkinter as tk
import random
class ChatBotApp:
def __init__(self, master):
self.master = master
master.title("Random ChatBot")
self.chat_history = tk.Text(master, state=tk.DISABLED)
self.chat_history.pack(padx=10, pady=10)
self.user_input = tk.Entry(master)
self.user_input.pack(padx=10, pady=10, fill=tk.X)
self.send_button = tk.Button(master, text="Send", command=self.send_message)
self.send_button.pack(padx=10, pady=10)
def send_message(self):
message = self.user_input.get()
self.user_input.delete(0, tk.END)
self.display_message("You: " + message)
response = self.generate_response(message)
self.display_message("Bot: " + response)
def generate_response(self, message):
# Define some sample responses
def generate_random_sentence():
subjects = ["I", "You", "He", "She", "They", "We"]
verbs = ["am", "are", "is", "was", "were"]
objects = ["happy", "sad", "hungry", "thirsty", "tired", "excited"]
subject = random.choice(subjects)
verb = random.choice(verbs)
obj = random.choice(objects)
sentences_01= f"{subject} {verb} {obj}."
return sentences_01
responses = [
generate_random_sentence(),
"That's interesting!",
"I'm not sure I understand.",
"Tell me more.",
"What do you think about that?",
"I see.",
"Could you elaborate?",
"Interesting, tell me more about it.",
"I'm sorry, I don't have an answer for that right now."
]
# Select a random response
return random.choice(responses)
def display_message(self, message):
self.chat_history.config(state=tk.NORMAL)
self.chat_history.insert(tk.END, message + '\n')
self.chat_history.config(state=tk.DISABLED)
self.chat_history.see(tk.END)
def main():
root = tk.Tk()
app = ChatBotApp(root)
root.mainloop()
if __name__ == "__main__":
main()