Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
from tkinter import *
from tkinter import messagebox
from profanityFilter import isSwearWord
from tkinter import simpledialog
from dictionary import dictionaryAPI
from help import helpMenu
from better_profanity import profanity
from translator import tranlateText
from userName import getUserName
from keywords import assignKeywords
profanity.load_censor_words()
botName = 'ChatBOT: '
root = Tk()
#TEXT SETTINGAS
messages = Text(root, bg='azure')
messages.grid()
messages.config(bg="azure", fg="black",font=("Times New Roman", 12))
input_user = StringVar()
inputField = Entry(root, text=input_user, bg='azure')
inputField.place(height=20, width=643, x=1, y=430)
#SCROLLBAR SETTINGS
scrollbar = Scrollbar(root)
scrollbar.place(height=407, width=20, x=623, y=1)
def appStart():
#TKINTER MAIN SETTINGS
root.deiconify()
root.title("Chat bot by Dovydas Rickus")
root.geometry('643x470')
root.iconbitmap('logo.ico')
root.resizable(False,False)
# HELP BUTTON
def helpGUI():
messages.insert(INSERT, '\n%s' % botName + 'Things I am capable for now:')
for word in helpMenu():
messages.insert(INSERT, '\n%s' % word)
return 'Break'
#TRANSLATION BUTTON
def translateGUI():
text = simpledialog.askstring(title="",
prompt="Text to translate")
if isSwearWord(text) == True:
messagebox.showwarning(title='PROFANITY ERROR', message='No curse words allowed')
return 'break'
language = simpledialog.askstring(title="",
prompt="To what Language? (Country Name)")
translation = tranlateText(text, language)
messages.insert(INSERT, '\n%s' % botName + translation)
#DICTIONARY BUTTON
def dictionaryGUI():
word = simpledialog.askstring(title="",
prompt="Word of which you want meaning:")
if isSwearWord(word) == True:
messagebox.showwarning(title='PROFANITY ERROR', message='No curse words allowed')
return 'break'
messages.insert(INSERT, '\n%s' % botName + dictionaryAPI(word))
#CALLING KEYWORDS.py
def mainLoop(event):
userName = getUserName() + ': '
userInput = inputField.get()
input_user.set('')
if isSwearWord(userInput) == True:
messagebox.showwarning(title='PROFANITY ERROR', message='No curse words allowed')
return 'break'
else:
messages.insert(INSERT, '\n%s' % userName + userInput)
messages.insert(INSERT,'\n%s' % botName + assignKeywords(userInput))
return "break"
#BUTTONS
b = Button(root,text='HELP',command=helpGUI,bg='light sky blue').place(x=1,y=407,height=23, width=214)
b1 = Button(root,text='TRANSLATION',command=translateGUI,bg='light sky blue').place(x=214,y=407,height=23, width=214)
b2 = Button(root, text='DICTIONARY', command=dictionaryGUI, bg='light sky blue').place(x=428, y=407, height=23, width=215)
# FUNCTIONS THAT CHANGES APP TO DARK/LIGHT
def lightMode():
b = Button(root, text='HELP', command=helpGUI, bg='light sky blue').place(x=1, y=407, height=23, width=214)
b1 = Button(root, text='TRANSLATION', command=translateGUI, bg='light sky blue').place(x=214, y=407, height=23,width=214)
b2 = Button(root, text='DICTIONARY', command=dictionaryGUI, bg='light sky blue').place(x=428, y=407, height=23,width=215)
messages.config(bg="azure", fg="black",font=("Times New Roman", 12))
inputField.config(bg="azure",fg='black')
menubar.config(activebackground="white", fg="black")
def darkMode():
b = Button(root, text='HELP', command=helpGUI, bg="DodgerBlue4", fg="white").place(x=1, y=407, height=23, width=214)
b1 = Button(root, text='TRANSLATION', command=translateGUI, bg="DodgerBlue4", fg="white").place(x=214, y=407, height=23,width=214)
b2 = Button(root, text='DICTIONARY', command=dictionaryGUI, bg="DodgerBlue4", fg="white").place(x=428, y=407, height=23,width=215)
root.config(bg="SkyBlue4")
messages.config(bg="SkyBlue4", fg="white",font=("Times New Roman", 12))
inputField.config(bg="SkyBlue4", fg="white")
menubar.config(bg="SkyBlue4", fg="white")
# DARK/LIGHT MENU
menubar = Menu(root)
dlmenu = Menu(menubar, tearoff=0)
dlmenu.add_command(label="DARK MODE", command=darkMode)
dlmenu.add_command(label="LIGHT MODE", command=lightMode)
menubar.add_cascade(label="UI MODE", menu=dlmenu)
#SCROLLBAR CONFIG
scrollbar.config(command=messages.yview)
#CALLS MAINLOOP UPON ENTER
inputField.bind('<Return>', mainLoop)
root.config(menu=menubar)
#ASK FOR USER NAME
def askUserName():
root.withdraw()
userInput = simpledialog.askstring(title="",
prompt="What's your name")
if userInput == '':
messagebox.showwarning(title='EMPTY NAME ERROR', message='You can not leave this entry empty!')
askUserName()
return 'break'
if isSwearWord(userInput) == True:
messagebox.showwarning(title='PROFANITY ERROR', message='You can not use swear words!')
askUserName()
return 'break'
userName = userInput.capitalize()
profanity.censor(userName)
messages.insert(INSERT, '%s' % botName+'How can I help you, ' +userName+'\n')
appStart()
userNameFile = open("userName.txt", "r+") #Saves user name in to file to get it whenever in code after
userNameFile.truncate()
userNameFile = open('userName.txt', 'w')
userNameFile.write(userName)
userNameFile.close()
askUserName()
root.mainloop()