File size: 12,582 Bytes
d20954e | 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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
from tkinter import *
from tkinter import ttk
import time
import tkinter.messagebox
import pyttsx3
import threading
from rihanna import rihanna
saved_username = ["You"]
window_size = "400x400"
class ChatInterface(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.master = master
# sets default bg for top level windows
self.tl_bg = "#EEEEEE"
self.tl_bg2 = "#EEEEEE"
self.tl_fg = "#000000"
self.font = "Verdana 10"
menu = Menu(self.master)
self.master.config(menu=menu, bd=5)
# Menu bar
# File
file = Menu(menu, tearoff=0)
menu.add_cascade(label="File", menu=file)
file.add_command(label="Clear Chat", command=self.clear_chat)
# file.add_separator()
file.add_command(label="Exit", command=self.chat_exit)
# Options
options = Menu(menu, tearoff=0)
menu.add_cascade(label="Options", menu=options)
# username
# font
font = Menu(options, tearoff=0)
options.add_cascade(label="Font", menu=font)
font.add_command(label="Default", command=self.font_change_default)
font.add_command(label="Times", command=self.font_change_times)
font.add_command(label="System", command=self.font_change_system)
font.add_command(label="Helvetica", command=self.font_change_helvetica)
font.add_command(label="Fixedsys", command=self.font_change_fixedsys)
# color theme
color_theme = Menu(options, tearoff=0)
options.add_cascade(label="Color Theme", menu=color_theme)
color_theme.add_command(label="Default", command=self.color_theme_default)
# color_theme.add_command(label="Night",command=self.)
color_theme.add_command(label="Grey", command=self.color_theme_grey)
color_theme.add_command(label="Blue", command=self.color_theme_dark_blue)
color_theme.add_command(label="Torque", command=self.color_theme_turquoise)
color_theme.add_command(label="Hacker", command=self.color_theme_hacker)
# color_theme.add_command(label='Mkbhd',command=self.MKBHD)
help_option = Menu(menu, tearoff=0)
menu.add_cascade(label="Help", menu=help_option)
# help_option.add_command(label="Features", command=self.features_msg)
help_option.add_command(label="About Rihanna", command=self.msg)
help_option.add_command(label="Develpoers", command=self.about)
self.text_frame = Frame(self.master, bd=6)
self.text_frame.pack(expand=True, fill=BOTH)
# scrollbar for text box
self.text_box_scrollbar = Scrollbar(self.text_frame, bd=0)
self.text_box_scrollbar.pack(fill=Y, side=RIGHT)
# contains messages
self.text_box = Text(self.text_frame, yscrollcommand=self.text_box_scrollbar.set, state=DISABLED,
bd=1, padx=6, pady=6, spacing3=8, wrap=WORD, bg=None, font="Verdana 10", relief=GROOVE,
width=10, height=1)
self.text_box.pack(expand=True, fill=BOTH)
self.text_box_scrollbar.config(command=self.text_box.yview)
# frame containing user entry field
self.entry_frame = Frame(self.master, bd=1)
self.entry_frame.pack(side=LEFT, fill=BOTH, expand=True)
# entry field
self.entry_field = Entry(self.entry_frame, bd=1, justify=LEFT)
self.entry_field.pack(fill=X, padx=6, pady=6, ipady=3)
# self.users_message = self.entry_field.get()
# frame containing send button and emoji button
# self.send_button_frame = Frame(self.master, bd=0)
# self.send_button_frame.pack(fill=BOTH)
#
# # send button
# self.send_button = Button(self.send_button_frame, text="Send", width=5, relief=GROOVE, bg='white',
# bd=1, command=lambda: self.send_message_insert(None), activebackground="#FFFFFF",
# activeforeground="#000000")
# self.send_button.pack(side=LEFT, ipady=8)
self.master.bind("<Return>", self.send_message_insert)
self.last_sent_label(date="No messages sent.")
status = ttk.Progressbar(self.entry_frame, orient=HORIZONTAL, length=180, mode='indeterminate')
status.pack(fill=X, side=BOTTOM)
status.start()
# t2 = threading.Thread(target=self.send_message_insert(, name='t1')
# t2.start()
def playResponce(self, responce):
x = pyttsx3.init()
#x.setProperty('rate', 120)
x.setProperty('volume', 100)
x.say(responce)
x.runAndWait()
def last_sent_label(self, date):
try:
self.sent_label.destroy()
except AttributeError:
pass
self.sent_label = Label(self.entry_frame, font="Verdana 7", text=date, bg=self.tl_bg2, fg=self.tl_fg)
self.sent_label.pack(side=LEFT, fill=X, padx=3)
def clear_chat(self):
self.text_box.config(state=NORMAL)
self.last_sent_label(date="No messages sent.")
self.text_box.delete(1.0, END)
self.text_box.delete(1.0, END)
self.text_box.config(state=DISABLED)
@staticmethod
def chat_exit():
exit()
@staticmethod
def msg():
tkinter.messagebox.showinfo("Rihanna v1.0",
'Rihanna is a chatbot developed for fun')
@staticmethod
def about():
tkinter.messagebox.showinfo("Rihanna Developers",
"Emeka")
def send_message_insert(self, message):
user_input = self.entry_field.get()
pr1 = "Human : " + user_input + "\n"
self.text_box.configure(state=NORMAL)
self.text_box.insert(END, pr1)
self.text_box.configure(state=DISABLED)
self.text_box.see(END)
ob = self.chat(user_input)
pr = "Rihanna : " + ob + "\n"
self.text_box.configure(state=NORMAL)
self.text_box.insert(END, pr)
self.text_box.configure(state=DISABLED)
self.text_box.see(END)
self.last_sent_label(str(time.strftime("Last message sent: " + '%B %d, %Y' + ' at ' + '%I:%M %p')))
self.entry_field.delete(0, END)
time.sleep(0)
t2 = threading.Thread(target=self.playResponce, args=(ob,))
t2.start()
# return ob
def font_change_default(self):
self.text_box.config(font="Verdana 10")
self.entry_field.config(font="Verdana 10")
self.font = "Verdana 10"
def font_change_times(self):
self.text_box.config(font="Times")
self.entry_field.config(font="Times")
self.font = "Times"
def font_change_system(self):
self.text_box.config(font="System")
self.entry_field.config(font="System")
self.font = "System"
def font_change_helvetica(self):
self.text_box.config(font="helvetica 10")
self.entry_field.config(font="helvetica 10")
self.font = "helvetica 10"
def font_change_fixedsys(self):
self.text_box.config(font="fixedsys")
self.entry_field.config(font="fixedsys")
self.font = "fixedsys"
def color_theme_default(self):
self.master.config(bg="#EEEEEE")
self.text_frame.config(bg="#EEEEEE")
self.entry_frame.config(bg="#EEEEEE")
self.text_box.config(bg="#FFFFFF", fg="#000000")
self.entry_field.config(bg="#FFFFFF", fg="#000000", insertbackground="#000000")
# self.send_button_frame.config(bg="#EEEEEE")
# self.send_button.config(bg="#FFFFFF", fg="#000000", activebackground="#FFFFFF", activeforeground="#000000")
self.sent_label.config(bg="#EEEEEE", fg="#000000")
self.tl_bg = "#FFFFFF"
self.tl_bg2 = "#EEEEEE"
self.tl_fg = "#000000"
# Dark
def color_theme_dark(self):
self.master.config(bg="#2a2b2d")
self.text_frame.config(bg="#2a2b2d")
self.text_box.config(bg="#212121", fg="#FFFFFF")
self.entry_frame.config(bg="#2a2b2d")
self.entry_field.config(bg="#212121", fg="#FFFFFF", insertbackground="#FFFFFF")
# self.send_button_frame.config(bg="#2a2b2d")
# self.send_button.config(bg="#212121", fg="#FFFFFF", activebackground="#212121", activeforeground="#FFFFFF")
# self.emoji_button.config(bg="#212121", fg="#FFFFFF", activebackground="#212121", activeforeground="#FFFFFF")
self.sent_label.config(bg="#2a2b2d", fg="#FFFFFF")
self.tl_bg = "#212121"
self.tl_bg2 = "#2a2b2d"
self.tl_fg = "#FFFFFF"
# Grey
def color_theme_grey(self):
self.master.config(bg="#444444")
self.text_frame.config(bg="#444444")
self.text_box.config(bg="#4f4f4f", fg="#ffffff")
self.entry_frame.config(bg="#444444")
self.entry_field.config(bg="#4f4f4f", fg="#ffffff", insertbackground="#ffffff")
# self.send_button_frame.config(bg="#444444")
# self.send_button.config(bg="#4f4f4f", fg="#ffffff", activebackground="#4f4f4f", activeforeground="#ffffff")
# self.emoji_button.config(bg="#4f4f4f", fg="#ffffff", activebackground="#4f4f4f", activeforeground="#ffffff")
self.sent_label.config(bg="#444444", fg="#ffffff")
self.tl_bg = "#4f4f4f"
self.tl_bg2 = "#444444"
self.tl_fg = "#ffffff"
def color_theme_turquoise(self):
self.master.config(bg="#003333")
self.text_frame.config(bg="#003333")
self.text_box.config(bg="#669999", fg="#FFFFFF")
self.entry_frame.config(bg="#003333")
self.entry_field.config(bg="#669999", fg="#FFFFFF", insertbackground="#FFFFFF")
# self.send_button_frame.config(bg="#003333")
# self.send_button.config(bg="#669999", fg="#FFFFFF", activebackground="#669999", activeforeground="#FFFFFF")
# self.emoji_button.config(bg="#669999", fg="#FFFFFF", activebackground="#669999", activeforeground="#FFFFFF")
self.sent_label.config(bg="#003333", fg="#FFFFFF")
self.tl_bg = "#669999"
self.tl_bg2 = "#003333"
self.tl_fg = "#FFFFFF"
# Blue
def color_theme_dark_blue(self):
self.master.config(bg="#263b54")
self.text_frame.config(bg="#263b54")
self.text_box.config(bg="#1c2e44", fg="#FFFFFF")
self.entry_frame.config(bg="#263b54")
self.entry_field.config(bg="#1c2e44", fg="#FFFFFF", insertbackground="#FFFFFF")
# self.send_button_frame.config(bg="#263b54")
# self.send_button.config(bg="#1c2e44", fg="#FFFFFF", activebackground="#1c2e44", activeforeground="#FFFFFF")
# self.emoji_button.config(bg="#1c2e44", fg="#FFFFFF", activebackground="#1c2e44", activeforeground="#FFFFFF")
self.sent_label.config(bg="#263b54", fg="#FFFFFF")
self.tl_bg = "#1c2e44"
self.tl_bg2 = "#263b54"
self.tl_fg = "#FFFFFF"
# Hacker
def color_theme_hacker(self):
self.master.config(bg="#0F0F0F")
self.text_frame.config(bg="#0F0F0F")
self.entry_frame.config(bg="#0F0F0F")
self.text_box.config(bg="#0F0F0F", fg="#33FF33")
self.entry_field.config(bg="#0F0F0F", fg="#33FF33", insertbackground="#33FF33")
# self.send_button_frame.config(bg="#0F0F0F")
# self.send_button.config(bg="#0F0F0F", fg="#FFFFFF", activebackground="#0F0F0F", activeforeground="#FFFFFF")
# self.emoji_button.config(bg="#0F0F0F", fg="#FFFFFF", activebackground="#0F0F0F", activeforeground="#FFFFFF")
self.sent_label.config(bg="#0F0F0F", fg="#33FF33")
self.tl_bg = "#0F0F0F"
self.tl_bg2 = "#0F0F0F"
self.tl_fg = "#33FF33"
# Default font and color theme
def default_format(self):
self.font_change_default()
self.color_theme_default()
def chat(self, msg):
theme = {"Torque": self.color_theme_turquoise, "Hacker": self.color_theme_hacker,
"Blue": self.color_theme_dark_blue,
"Grey": self.color_theme_grey, "Default": self.color_theme_default}
msg = msg.lower().strip()
if msg[:len('change theme ')] == 'change theme ':
th = msg[len('change theme '):].capitalize()
if th in theme:
theme[th]()
return f'Theme changed to {th}'
else:
return f'cannot find theme {th}'
else:
return str(rihanna(msg)['say'])
root = Tk()
a = ChatInterface(root)
root.geometry(window_size)
root.title("Rihanna")
root.iconbitmap('bird.ico')
root.mainloop()
|