tkinter psyillogical game

Not sure if blogger will let me fit all this in...

Here it is, but I know it can use some more clean up.
It was a lot like pygame so once I got the rythem it wasn't so bad, but some stuff was quite tricky.
As always, see something, drop me a note!  I'd love to hear from anyone.

The Tkinter file:
* pillow not used for game
##  The PIL  and Image stuff was not used, so I took it out, but will use it for the fan-fic game
pyGUI1.py


from PIL import Image
from PIL import ImageTk
import tkinter as tk
from psychillogical import Questionaire, Psychillogical

class MygewyWindow(tk.Frame):

def __init__(self, master = None):
super().__init__(master)
self.master = master
self.special_font = ("helevitca", 16, "bold")
self.special_font_8 = ("helevitca", 8, "bold")
self.canvas = None
self.frame_text = None
self.c2_text = None
self.m_text = None

self.config_frames()
self.label_frame()
self.config_buttons()
self.navbar()


def label_frame(self):
#label_frame needs expand option to be visible as a frame instead
# of just a label
color = "papaya whip"
self.label_frame1 = tk.LabelFrame(self.master, bg=color, text="questions:")
self.label_frame1.pack(side="top", fill='both', expand="yes")
self.buttonf_a = tk.Button(self.master, bg=color)
self.buttonf_a["text"] = "A"
self.buttonf_a["font"] = self.special_font
self.buttonf_a.pack(side='left', fill='x', expand='yes')


self.buttonf_b = tk.Button(self.master, bg=color)
self.buttonf_b["text"] = "B"
self.buttonf_b["font"] = self.special_font
self.buttonf_b.pack(side='left',fill='x', expand='yes')


self.buttonf_c = tk.Button(self.master, bg=color)
self.buttonf_c["text"] = "C"
self.buttonf_c["font"] = self.special_font
self.buttonf_c.pack( side='left', fill='x', expand='yes')
self.buttonf_c.pack()


self.buttonf_d = tk.Button(self.master, bg=color)
self.buttonf_d["text"] = "D"
self.buttonf_d["font"] = self.special_font
self.buttonf_d.pack(side='left',fill="x", expand='yes')

self.buttonf_e = tk.Button(self.master, bg=color)
self.buttonf_e["text"] = "E"
self.buttonf_e["font"] = self.special_font
self.buttonf_e.pack(side='left',fill="x", expand='yes')


def config_frames(self):
self.master.title("Another Noodle")
self.mycontainer2 = tk.Frame(self.master, bg="old lace")
self.mycontainer2.pack(side="top", fill="both", expand="yes")
self.mycontainer = tk.Frame(self.master, bg="floral white")
self.mycontainer.pack(side="bottom", expand = "no")

def config_buttons(self):
self.button2 = tk.Button(self.mycontainer)
self.button2["text"] = "QUIT"
self.button2["font"] = self.special_font
self.button2["background"] = "old lace"
self.button2["foreground"] = "purple"
self.button2["command"] = root.destroy
self.button2.pack(side="left")


def navbar(self):
self.navbargame = tk.Menu(self.master, bg="bisque")
self.master.config(menu=self.navbargame)
self.quit_exit = tk.Menu(self.navbargame)
self.quit_exit.add_command(label="Exit", command=root.destroy)
self.quit_exit.add_command(label="Back", command=self.game_back)
self.navbargame.add_cascade(label="Options", menu=self.quit_exit)
root.config(menu=self.navbargame)

def game_back(self):
try:
game.running('back')
except:
pass


def show_txt_master(self, filltext):
color = self.master["background"]
self.m_rframe = tk.LabelFrame(self.master, bg = 'white')
self.m_rframe.pack(side = "top", fill="both",  expand = 'yes')
self.m_text = tk.Label(self.m_rframe, bg=color, text = filltext)
self.m_text.pack(fill='both', expand='yes')


def show_txt(self, filltext):
color = self.label_frame1["background"]
self.frame_text = tk.Label(self.label_frame1, bg=color, text=filltext)
self.frame_text['font'] = 'TkDefaultFont'
self.frame_text.pack(fill="both", expand="yes")

def show_txt_c2(self, filltext):
color = self.mycontainer2["background"]
self.c2_text = tk.Label(self.mycontainer2, bg=color, text=filltext)
self.c2_text["font"] = self.special_font_8
self.c2_text.pack(fill="both", expand="yes")

def show_txt_c3(self, filltext):
color = self.label_frame1["background"]
self.frame_text = tk.Label(self.label_frame1, bg=color, text=filltext)
self.frame_text['font'] = self.special_font
self.frame_text.pack(fill="both", expand="yes")

def playbutton(self):
color = self.mycontainer2["background"]
self.playbutton = tk.Button(self.mycontainer2)
self.playbutton["text"] = "PLAY"
self.playbutton["font"] = self.special_font
self.playbutton["background"] = color
self.playbutton["foreground"] = "purple"
self.playbutton["command"] = self.play_yes
self.playbutton.pack()

def play_yes(self):
self.playbutton.destroy()
self.clear_top()
game.running('start')

def play_again_yes(self):
game.angry = 0
game.passive = 0
game.normal = 0
game.batty = 0
game.uncooperative = 0
game.impulsive = 0
self.playbutton2.destroy()
self.clear_top()
game.running('start')

def clear_top(self):
if self.c2_text != None:
self.c2_text.pack_forget()
else:
pass

def clear_bottom(self):
if self.frame_text != None:
self.frame_text.pack_forget()
else:
pass

def clear_responses(self):
if self.m_text != None:
self.m_rframe.pack_forget()
self.m_text.pack_forget()
else:
pass

def disable_back(self):
self.quit_exit.entryconfig('Back', state='disable')

def enable_back(self):
self.quit_exit.entryconfig('Back', state='normal')

def button_activity(self, event):
if event in ['number3', 'number4', 'number5', 'number6', 'number7','number8','number9','number10', 'number11']:
self.buttonf_a["command"] = lambda: [game.running(event, 'a'), game.keep_score2('a')]
self.buttonf_b["command"] = lambda: [game.running(event, 'b'), game.keep_score2('b')]
self.buttonf_c["command"] = lambda: [game.running(event, 'c'), game.keep_score2('c')]
self.buttonf_d["command"] = lambda: [game.running(event, 'd'), game.keep_score2('d')]
self.buttonf_e["command"] = lambda: [game.running(event, 'e'), game.keep_score2('e')]
elif event == 'back':
self.buttonf_a["command"] = lambda: game.running(event, 'a')
self.buttonf_b["command"] = lambda: game.running(event, 'b')
self.buttonf_c["command"] = lambda: game.running(event, 'c')
self.buttonf_d["command"] = lambda: game.running(event, 'd')
self.buttonf_e["command"] = lambda: game.running(event, 'e')
else:
self.buttonf_a["command"] = lambda: [game.running(event, 'a'), game.keep_score('a')]
self.buttonf_b["command"] = lambda: [game.running(event, 'b'), game.keep_score('b')]
self.buttonf_c["command"] = lambda: [game.running(event, 'c'), game.keep_score('c')]
self.buttonf_d["command"] = lambda: [game.running(event, 'd'), game.keep_score('d')]
self.buttonf_e["command"] = lambda: [game.running(event, 'e'), game.keep_score('e')]

def play_again(self):
color = self.mycontainer2["background"]
self.playbutton2 = tk.Button(self.mycontainer2)
self.playbutton2["text"] = "PLAY AGAIN?"
self.playbutton2["font"] = self.special_font
self.playbutton2["background"] = color
self.playbutton2["foreground"] = "purple"
self.playbutton2["command"] = self.play_again_yes
self.playbutton2.pack()



##############   game() ###################
class PsyTest(object):
def __init__(self):
self.test_place = 0
self.angry = 0
self.passive = 0
self.normal = 0
self.batty = 0
self.impulsive = 0
self.uncooperative = 0
self.questions = Questionaire()
self.myapp = MygewyWindow(root)
self.intro()
self.myapp.disable_back()

def start(self):
self.myapp.mainloop()

def intro(self):
self.myapp.playbutton()
self.myapp.show_txt_c2(self.questions.introduction)


def running(self, event=None, response=None):
#print("*" * 25)
next_event = self.get_next(event)
p_event = self.get_previous(event)
current = self.get_current(event)
#print(f"current at start = {current}")
#print(f"self.test_place start of running = {self.test_place}")
#print(f"event at start = {event}")
#print(f" p _ event at start = {p_event}")
#print(f"next_event at start = {next_event}")

if event == 'start' or p_event == 'start':
self.test_place = 0
self.myapp.clear_top()
self.myapp.clear_bottom()
self.myapp.clear_responses()
next_Q = self.questions.get_it('first')
text = next_Q.get_question()
answers = next_Q.get_answers()
self.myapp.show_txt_c2(text)
self.myapp.show_txt(answers)
self.myapp.button_activity('first')

elif event == 'playbutton':
defaults = "press the play button to begin"
self.myapp.show_txt_c3(defaults)

elif next_event == None:
self.myapp.clear_top()
self.myapp.clear_bottom()
self.myapp.clear_responses()
self.myapp.disable_back()
###self.myapp.remove_back()
message = "End of completely faked test."
self.myapp.show_txt_c2(message)
scoreing = self.calc_scores()
#score = " score = " + str(self.angry)
self.myapp.show_txt(scoreing)
self.myapp.play_again()

elif event == 'back':
print("event == back  block running")

self.test_place -= 1
self.myapp.clear_top()
self.myapp.clear_bottom()
self.myapp.clear_responses()
next_Q = self.questions.get_it(p_event)
next_text = next_Q.get_question()
answers = next_Q.get_answers()
self.myapp.show_txt_c2(next_text)
self.myapp.show_txt(answers)
#print(f"**** next(prev) _ event = {p_event}")
self.myapp.button_activity(p_event)




else:
print("ELSE of running in Game executing")
print(self.test_place)
print(f"next_event = {next_event}")
self.myapp.clear_top()
self.myapp.clear_bottom()
self.myapp.clear_responses()
self.myapp.enable_back()
next_Q = self.questions.get_it(next_event)
next_text = next_Q.get_question()
answers = next_Q.get_answers()
self.test_place += 1
self.myapp.show_txt_c2(next_text)
self.myapp.show_txt(answers)
#print(f"**** next _ event = {next_event}")
if response:
self.hmmm = current.get_response(response)
self.myapp.show_txt_master(self.hmmm)
self.myapp.button_activity(next_event)
else:
self.myapp.button_activity(next_event)



def get_next(self, event):
possibles = ['first', 'number1', 'number2', 'number3','number4','number5','number6','number7','number8',
'number9','number10','number11']
print("get next")
print(event)

if event == 'start':
return 'first'
elif event == 'back':
x = possibles[self.test_place]
return x
elif event == 'playbutton':
pass
else:
i = possibles.index(event)
if i + 1 < 12:
return possibles[i + 1]
else:
return None

def get_previous(self, event):
possibles = ['first', 'number1', 'number2', 'number3','number4','number5','number6','number7','number8',
'number9','number10','number11']
print("get_previous")
print(event)

if event == 'start' or event == 'playbutton' or event == 'first':
return 'first'
elif event == 'back':
x = possibles[self.test_place - 1]
if x == 'number11':
return 'start'
else:
return x
elif event == 'playbutton':
pass
else:
i = possibles.index(event)
if i > 0:
return possibles[i - 2]
else:
return None

def get_current(self, event):
print("get current")
print(event)

if event == 'start' or event == 'playbutton' or event == 'first':
current = self.questions.get_it('first')
return current
elif event == 'back':
return None
else:
current = self.questions.get_it(event)
return current

def keep_score(self, answer):
if answer == 'a':
self.angry += 2
elif answer == 'b':
self.passive += 1
elif answer == 'c':
self.normal += 2
elif answer == 'd':
self.batty += 3
elif answer == 'e':
self.uncooperative += 2
else:
pass
def keep_score2(self, answer):
#impulsive, batty, angry, chill, balance
if answer =='a':
self.passive -=1
self.impulsive += 2
elif answer =='b':
self.batty += 2
elif answer =='c':
self.angry += 3
elif answer == 'd':
self.normal += 2
elif answer == 'e':
self.angry -=1
self.passive += 1
self.normal += 1
else:
pass



def calc_scores(self):
self.hulk = (self.angry + self.impulsive + 2) // 2
self.chill = (self.passive + self.normal + self.uncooperative + 2)//2
self.alert = (self.angry + self.batty + self.uncooperative + self.impulsive + 4)//4
self.clear = (self.normal + self.passive + 2)//2
calc_string = """ """
calc_string = calc_string + "\n" + "Hulk level = " + str(self.hulk)
calc_string = calc_string + "\n" + "chill level = " + str(self.chill)
calc_string = calc_string + "\n" + "normal level = " + str(self.clear)
calc_string = calc_string + "\n" + "bats level = " + str(self.alert)

return calc_string



root = tk.Tk()
root["background"] = "old lace"


# resizable --- make the size constant with False
#root.resizable(width=False, height=False)
#default a size
root.geometry('{}x{}'.format(800, 400))

game = PsyTest()
game.start()

################################
The psychillogical/questionnaire file:
psychillogical.py


class Psychillogical(object):

def __init__(self, question):
self.question = question
self.responses = {}
self.answers = []

def respond(self, answer):
result = self.responses.get(answer, None)
print(result)
def get_response(self, answer):
result = self.responses.get(answer, None)
return result
def add_responses(self, responses):
self.responses.update(responses)
def set_answers(self, alist):
self.answers = alist
def show_question(self):
print(self.question)
def get_question(self):
return self.question
def show_answers(self):
for i in self.answers:
print(i)
def get_answers(self):
string_return = """ """
for i in self.answers:
string_return = string_return + i + "\n"
return string_return



class Questionaire(object):
    introduction = """ Welcome to the completely unethical and unscientific psychological test.
           Explore your basic emotional skill set with these randomly unprofessional
           questions that have no real life application."""
    question_list = [" 1. You have stepped on bee, and it died stinging you. ",
      "2. An elderly lady is in the way at the liquor store, and can't hear you asking her to move.",
      "3. A stranger's child has knocked over your morning coffee with his large bouncy ball.",
      "4. Someone is trying to dramatically tell you a story about thier trip to a zoo.",
      "5. A clicking noise is getting louder as you try to rest.",
      "6. Someone has defiled a church and placed thier landmark cross upside down.",
      "7. You have awakened in a field of cotton candy blossoms whose neon filimants light up the sky.",
      "8. The bicyclist in front of you refuses to get off the road and continues to ride in the middle of the lane as you honk.",
      "9. The narrator said what? ",
      "10. A woman has sneezed and blood splatters on the floor in front of you.",
      "11. A mysterious and dangerous looking individual is approaching you rapidly.",
      "12. Are you tired of questions? "]



    number1 = Psychillogical(question_list[0])
    number2 = Psychillogical(question_list[1])
    number3 = Psychillogical(question_list[2])
    number4 = Psychillogical(question_list[3])
    number5 = Psychillogical(question_list[4])
    number6 = Psychillogical(question_list[5])
    number7 = Psychillogical(question_list[6])
    number8 = Psychillogical(question_list[7])
    number9 = Psychillogical(question_list[8])
    number10 = Psychillogical(question_list[9])
    number11 = Psychillogical(question_list[10])
    number12 = Psychillogical(question_list[11])
    #  number 1  set up "Bee sting"
    # anger, passive, chill, aggressive, batshit, uncooperative Game.score1()
    onelist = ['a: Stomp on it!',
               'b: Flick it\'s corpse away.',
               'c: Just glad no ones allergic, and no one got hurt.',
               'd: Find the hive and kill them all!',
               'e: Bugs... gross.' ]
    number1.set_answers(onelist)


    number1.add_responses({'a': 'Yes, crunch crunch.',
                           'b': 'No one will notice.',
                           'c': 'The bee got hurt.',
                           'd': 'Let me just get my big notebook.',
                           'e': 'Do bee, dobee do..'
                            })
    #  number 2  set up "getting beer"
    # Game.score1()
    twolist = ['a: Shout and push through to the Vodka.',
               'b: Walk around to a different isle but give her the finger.',
               'c: Get closer and ask if she needs help.',
               'd: Go tell the manager an old lady is having a stroke in the whisky isle.',
               'e: I don\'t drink' ]
    number2.set_answers(twolist)
    number2.add_responses({'a': 'Vegetables are important.',
                           'b': 'You don\'t drink anyways right?',
                           'c': 'How sweet... psycho.',
                           'd': 'You can drink your beer outside and watch. I see. <going out for more paper>',
                           'e': 'I see.' })

    #  number 3  set up "the kid spilled my coffee"
    # Game.score1()
    threelist = ['a: Be very loud about how much coffee means to you.',
                 'b: Get a towel to clean the coffee, and flip off the kids parents.',
                 'c: Laugh it off and get some tea.',
                 'd: Take the ball and rip it apart with your bare hands.',
                 'e: Follow the parents home so you can send them hate mail later.']
    number3.set_answers(threelist)
    number3.add_responses({'a': 'Coffee is life.',
                           'b': 'I have a feeling that finger might get tired.',
                           'c': 'Tea sounds delicious.',
                           'd': 'That ball deserved what it got.',
                           'e': 'Traffic can be tricky.' })

    #  number 4  set up  "zoo story"
    # Game.score1()
    fourlist = ['a: Tell them you hate zoos and have somewhere to be.',
                'b: Stop them to tell them how long giraffe\'s necks are.',
                'c: Show interest and engage in the conversation.',
                'd: Rage about the captivity of endangered species and suggest breaking them free.',
                'e: Fantasize about being a part of an orangutan worshipping cult.']
    number4.set_answers(fourlist)
    number4.add_responses({'a': 'Zoo SHMOO. Right?',
                           'b': 'Yes, everyone needs to know what you know.',
                           'c': 'How very social. It\'s ok to answer honestly.',
                           'd': 'Too right! <slowly hiding the zoo contributions certificate>',
                           'e': 'They are amazing apes.'})

    #  number 5  set up  "clicking noise"
    # impulsive, batshit, angry, chill, balance Game.score2()
    fivelist = ['a: Wake up your partner for some nookie.',
                'b: Start making your own louder noise to scare the gremlin away.',
                'c: Go tear apart whatever is making the sound.',
                'd: Play some techno and meditate.',
                'e: Find the noise and try to fix it.']
    number5.set_answers(fivelist)
    number5.add_responses({'a': 'That, well there is that.',
                           'b': 'I didn\'t know they could be scared, tell me more.',
                           'c': 'With tools, or with your words?',
                           'd': 'What\'s in that tea?',
                           'e': 'And that\'s how the horror movie begins?'})
    #  number 6  set up  "religion"
    # impulsive, batshit, angry, chill, balance Game.score2()
    sixlist = ['a: Start a facebook post to find the person(s) involved.',
               'b: Go prepare for the apocolypse.',
               'c: Punch the first person who laughs about it',
               'd: Go have some Tea.',
               'e: Offer to help the church fix it.']
    number6.set_answers(sixlist)
    number6.add_responses({'a': 'To congratulate them, or turn them in?',
                           'b': 'Did you say you have a bomb shelter?',
                           'c': 'Sacred objects, yes, I see.',
                           'd': 'I\'d sure like to try that Tea.',
                           'e': 'How very charitable. <making notes>'})
    #  number 7 set up  "dream or not a dream "
    # impulsive, batshit, angry, chill, balance Game.score2()
    sevenlist = ['a: Go taste the cotton candy.',
                 'b: Enjoy it, it\'ll disappear soon.',
                 'c: Start looking for something to kick.',
                 'd: This is a dream, explore.',
                 'e: Establish what is reality and what is not.']
    number7.set_answers(sevenlist)
    number7.add_responses({'a': 'I guess it would be tempting.',
                           'b': 'So, this is normal for you?',
                           'c': 'Disorientation can be frightening.',
                           'd': 'Ever seen the movie, \'The Cell\'?',
                           'e': 'Does it need established at that point?'})
    #  number 8 set up  "share the road"
    # impulsive, batshit, angry, chill, balance Game.score2()
    eightlist = ['a: Honk and speed around the person.',
                 'b: Pull up next to them so you can memorize the face.',
                 'c: Honk and Yell and speed around them, then slam the brakes.',
                 'd: Put on some music and enjoy a slow ride.',
                 'e: Wait for a chance to safely pass.']
    number8.set_answers(eightlist)
    number8.add_responses({'a': 'Do you drive like that often?',
                           'b': 'Random citizen\'s faces a hobby collection?',
                           'c': 'Reaction time is important. <flip to a new sheet of paper>',
                           'd': 'What kind of bowl do you have for breakfast?',
                           'e': 'oh yeah, I\'d do that too.'})
    #  number 9 set up  "narrator"
    # impulsive, batshit, angry, chill, balance Game.score2()
    ninelist = ['a: Do something random to see if the narrator notices',
                'b: Get more supplies for the bomb shelter.',
                'c: Break stuff until it shuts up.',
                'd: Offer the narrator Tea.',
                'e: Investigate as to where the voice is comming from.']
    number9.set_answers(ninelist)
    number9.add_responses({'a': 'Are you flipping me off?',
                           'b': 'Spam is definitely under-rated.',
                           'c': 'Not the computer though, right?',
                           'd': 'Yes, please.',
                           'e': 'Interesting.'})
    #  number 10 set up  "germs and blood"
    # impulsive, batshit, angry, chill, balance Game.score2()
    tenlist = ['a: Run home and prepare a bath of luke warm bleach water.',
               'b: Kill her before she begins the mass extinction of mankind.',
               'c: Throw Pine-Sol at her, and tell her to cover her face if she\'s sick.',
               'd: Calmly exit and find some hand sanitizer and burritos.',
               'e: Ask her if she needs to be taken to a doctor.']
    number10.set_answers(tenlist)
    number10.add_responses({'a': 'Is that your natural hair color?',
                            'b': 'I see..........................',
                            'c': 'Love the smell of Pine-Sol in the morning.',
                            'd': 'Now I\'m hungry. Thanks.',
                            'e': 'You\'re right, Maybe 911.'})
    #  number 11 set up  "perception danger"
    # impulsive, batshit, angry, chill, balance Game.score2()
    elevenlist = ['a: Wink at them.',
                  'b: Approach them to tell them the benefits of floppy trout storage.',
                  'c: Put on your most intimidating face and get ready for a fight.',
                  'd: It has nothing to do with you, smile and move on.',
                  'e: Put your hand up, and firmly state, "What is the meaning of this?"']
    number11.set_answers(elevenlist)
    number11.add_responses({'a': 'Wink wink, nudge nudge.',
                            'b': 'Do tell me about this floppy trout storage.',
                            'c': 'Fisticuffs, too right chap.',
                            'd': 'What a wonderful place to be.',
                            'e': 'What if they just got stung by a bee?'})

    # number 12  final question
    twelvelist = ['a: YES! NO! Maybe!',
                  'b: I quite like questions.',
                  'c: Another God Damned question and I\'ll kick something!',
                  'd: Got any brownies?',
                  'e: Just looking for something to do.']
    number12.set_answers(twelvelist)
    number12.add_responses({'a': 'I don\'t have any more available yet.',
                            'b': 'Maybe I\'ll make some more.',
                            'c': 'We are done, let me gather the score.',
                            'd': 'Do you have brownies?',
                            'e': 'Me too.  Me too. '})
    lookup_next = {'first': number1, 'number1': number2, 'number2': number3, 'number3': number4, 'number4': number5,
    'number5': number6, 'number6': number7, 'number7': number8, 'number8': number9, 'number9': number10,
     'number10': number11, 'number11': number12}

    def get_it(self, number):
        return self.lookup_next.get(number)






Comments

Popular posts from this blog

playing with color in powershell python

JavaScript Ascii animation with while loops and console.log

playing with trigonometry sin in pygame