-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGUIchatbot.py
88 lines (66 loc) · 3.04 KB
/
GUIchatbot.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
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
import tkinter
from tkinter import ttk
from tkinter import tix
import os
##start GUI
root = tkinter.Tk()
##Window name
root.title('GameBot')
#create container frame
frameStyle = ttk.Style()
frameStyle.configure("frame.TFrame", padx="20", pady="20", relief="flat", background="#0a0082")
###
##would like the window to be resizable and for the two text frames to auto adjust size.
###
frame = ttk.Frame(root, style="frame.TFrame")
frame.pack()
##add a text box - bg white - ideal solution to convert the text box to a frame and have individual text boxes generated per chat,
##or alternate the colout of the text highlight
chatWindow = tkinter.Text(frame, state="disabled", relief="raised", wrap="word")
chatWindow.pack(fill="x", padx="10", pady="5")
scrollbar = ttk.Scrollbar(chatWindow)
scrollbar.pack(side = "right", fill="y" )
scrollbar.config(command = chatWindow.yview )
def writeToLog(msg):
numlines = chatWindow.index('end - 1 line').split('.')[0]
chatWindow['state'] = 'normal'
if chatWindow.index('end-1c')!='1.0':
chatWindow.insert('end', '\n')
chatWindow.insert('end', msg)
chatWindow['state'] = 'disabled'
def userTextInput():
userInput = input.userTextBox.get("1.0", "END-1c")
userTextBox.delete(0,END)
userTextBox = tkinter.Text(frame, bg="#87ceeb", relief="sunken", wrap="word")
userTextBox.pack(fill="x", padx="10")
enter_btn = ttk.Button(frame, text="enter", command=userTextInput)
enter_btn.pack(side="right", padx="10")
exit_btn = ttk.Button(frame, text="exit", command=root.quit)
exit_btn.pack(side="right", padx="10")
#end GUI code
root.mainloop()
##End GUI
userName = input('what is your name? \n')
print('Hello ', userName)
gameType = input('Are we going to play \'eye spy\' or \'odd one out\' ? \n')
if gameType == 'eye spy':
print('great let\'s play eye spy')
eyeSpyItem = input('Eye spy with my little eye, something Beginning with M \n')
if eyeSpyItem == 'Mouse' or eyeSpyItem == 'mouse':
print('A ', eyeSpyItem, ' how did you guess! ')
elif eyeSpyItem == 'Mirror' or eyeSpyItem == 'mirror':
print(eyeSpyItem, '! that\'s the right answer. Well done', userName)
else:
print('Sorry that\'s not the right answer, better luck next time!')
elif gameType == 'odd one out':
print('Great, this will be fun,')
print('choose the odd one out! \n Dog \n Cat \n Spoon')
answer = 'blank'
while answer.strip() != 'Spoon' or 'spoon':
answer = input()
if answer == 'Spoon' or answer =='spoon': print('Well done ', userName, '! \n You got it right.')
elif answer == 'Dog' or answer == 'dog' or answer == 'Cat' or answer == 'cat': print('Sorry ', userName, '\n', answer, ' is not the right answer, try again')
else: print('I dont understand, please select from Dog, Cat, or Spoon')
else:
print('I am unable to help with that, Goodbye', userName)
print('Thanks for playing ', userName, ' until next time!')