Hi All,

I am working on a project for school. Notice that I am a liberal arts major. My project is to develop a multiple choice test. I decided it would be a cool time to teach myself how to program so people could take the test on the computer. I didn't have to do it that way, I could have used anything like survey monkey, etc. but I wanted to learn it. That was dumb but I got pretty far and I really want to finish.

Anyways my code is below I have questions on two parts:

  1. im trying to create a start screen below I have copies over some code so thats why there is quit functions and what not.
    If you could point me in the right direction in creating a start page that would be great.

    1. i'm also looking to put the answers into a list how would the -if statments- look if i were to give an answer based on how many a's were chosen or b's, c's or d's

    Both questions can also be found as comments below in the location I am working. Thanks for any help. I graduate soon and I promise to give you the best french fries ever when you come into my place of employment after I get my history degree...

    #!/usr/bin/env python
    '''
    __Apr04_EX1.py__ = "TAT PROGRAM"
    
    __author__ = "Jim"
    __email__ = "removed"
    __copyright__ = "Copyright 2012, Spring '12"
    
    __python version__ = "2.7.2"
    __last updated__ = "april 10, 2012"
    
    open in cmd
    '''
    
    
    
    #-----import modules-----
    import sys, pygame, time, random
    
    
    #-----global variables-----
    pygame.init()
    window_size = 800, 533 
    window = pygame.display.set_mode((window_size))
    pygame.mouse.set_visible(1) #(1=true or 0=false) Mouse click answer
    pygame.display.set_caption('Thematic Apperception Test') 
    
    
    #-----function definitions-----
    def font():
        basicFont = pygame.font.SysFont(None, 50)
        questionFont = pygame.font.SysFont(None, 30)
        startcolor = (255,255,255)
        questioncolor = (50,55,25)
        text = basicFont.render('Thematic Apperception Test', True, startcolor)
        text2 = questionFont.render("1) Who are these people?", True, questioncolor)
        text3 = questionFont.render("A Husband and wife", True, questioncolor)
        text4 = questionFont.render("A businessman and his mistress", True, questioncolor)
        text5 = questionFont.render("A murderer and his victim", True, questioncolor)
        text6 = questionFont.render("A doctor and his patient", True, questioncolor)
        text7 = questionFont.render("I don't know", True, questioncolor)
    
        text2_2 = questionFont.render("2) What are they feeling?", True, questioncolor)
        text3_2 = questionFont.render("Happy and/or tired", True, questioncolor)
        text4_2 = questionFont.render("Incomplete and/or unhappy", True, questioncolor)
        text5_2 = questionFont.render("Sad and/or lost", True, questioncolor)
        text6_2 = questionFont.render("Accomplished and/or healthy", True, questioncolor)
        text7_2 = questionFont.render("I don't know", True, questioncolor)
    
        text2_3 = questionFont.render("3) What are they thinking?", True, questioncolor)
        text3_3 = questionFont.render("What they are doing tomorrow", True, questioncolor)
        text4_3 = questionFont.render("how they cant wait to meet again", True, questioncolor)
        text5_3 = questionFont.render("how to cover up a mistake", True, questioncolor)
        text6_3 = questionFont.render("how to fix a problem", True, questioncolor)
        text7_3 = questionFont.render("I don't know", True, questioncolor)
    
        text2_4 = questionFont.render("4) What are they hoping for?", True, questioncolor)
        text3_4 = questionFont.render("To have a nice day", True, questioncolor)
        text4_4 = questionFont.render("To stop living a lie", True, questioncolor)
        text5_4 = questionFont.render("That this will be covered up", True, questioncolor)
        text6_4 = questionFont.render("That it was successful", True, questioncolor)
        text7_4 = questionFont.render("I don't know", True, questioncolor)
    
        text2_5 = questionFont.render("5) What led to this situation?", True, questioncolor)
        text3_5 = questionFont.render("A willing vacation", True, questioncolor)
        text4_5 = questionFont.render("An urge to run away", True, questioncolor)
        text5_5 = questionFont.render("A hateful relationship", True, questioncolor)
        text6_5 = questionFont.render("A call for help", True, questioncolor)
        text7_5 = questionFont.render("I don't know", True, questioncolor)
    
        text2_6 = questionFont.render("6) What's the outcome?", True, questioncolor)
        text3_6 = questionFont.render("They return back home", True, questioncolor)
        text4_6 = questionFont.render("Split up and move on", True, questioncolor)
        text5_6 = questionFont.render("Panic and run", True, questioncolor)
        text6_6 = questionFont.render("A new start", True, questioncolor)
        text7_6 = questionFont.render("I don't know", True, questioncolor)
    
    
        return [
                text, text2, text3, text4, text5, text6, text7,
                text2_2, text3_2, text4_2, text5_2, text6_2, text7_2,
                text2_3, text3_3, text4_3, text5_3, text6_3, text7_3,
                text2_4, text3_4, text4_4, text5_4, text6_4, text7_4,
                text2_5, text3_5, text4_5, text5_5, text6_5, text7_5,
                text2_6, text3_6, text4_6, text5_6, text6_6, text7_6
                ]
    
    def startpage():
        background = pygame.Rect(0,0,800,533)
        startimage = pygame.image.load('background.gif')
        return [startimage, background]
    
    def background():
        background = pygame.Rect(0,0,800,533)
        image = pygame.image.load('TAT_1.jpg')
        return [image, background]
    
    
    def button():
        button_a = pygame.image.load('a_Button.png')
        button_b = pygame.image.load('b_Button.png')
        button_c = pygame.image.load('c_Button.png')
        button_d = pygame.image.load('d_Button.png')
        button_e = pygame.image.load('e_Button.png')
    
        rec_a = pygame.Rect(435,180,20,20)
        rec_b = pygame.Rect(435,220,20,20)
        rec_c = pygame.Rect(435,260,20,20)
        rec_d = pygame.Rect(435,300,20,20)
        rec_e = pygame.Rect(435,340,20,20)
    
        return [button_a, button_b, button_c, button_d, button_e,rec_a,rec_b,rec_c,rec_d,rec_e]
    
    def isPointInsideRect(x, y, rect):
        if (x > rect.left) and (x < rect.right) and (y > rect.top) and (y < rect.bottom):
            return True
        else:
            return False
    
    
    
    #create a button for each answer 
    
    #-----main body-----
    text  = font()
    back  = background() 
    press = button()
    start = startpage()
    #-----draw objects on screen-----
    answers = []
    mouse =False
    startscreen =False
    game =True
    screen =False
    
    
    ##???????????## I'm trying to create a start screen below
    ##??????????## I have copies over some code so thats why there is quit functions and what not.
    ##??????????## If you could point me in the right direction in creating a start page that would be great.
    '''
    
    while True:
        if startscreen==True:
            pass
        elif game==True:
    
        for event in pygame.event.get():
            if (event.type == pygame.QUIT) or (event.type==pygame.KEYDOWN and event.key==pygame.K_ENTER):
                    sys.exit()
            elif (event.type == pygame.MOUSEBUTTONDOWN and event.button == 1):
                    position = pygame.mouse.get_pos()
                    mouse = True
    
    
        if len(answers)<=0:
            window.fill((0,0,0)) 
            window.blit(start[0], start[1])
    
        ##use in start and end screen (change button value)f t
            for event in pygame.event.get():
                if (event.type == pygame.QUIT) or (event.type==pygame.KEYDOWN and event.key==pygame.K_ESCAPE):
                    sys.exit()
                elif (event.type == pygame.MOUSEBUTTONDOWN and event.button == 1):
                    position = pygame.mouse.get_pos()
                    mouse = True
    '''
            if mouse == True and isPointInsideRect(position[0], position[1], press[5]):
                answers.append("A")
                mouse = False
            elif mouse == True and isPointInsideRect(position[0], position[1], press[6]):
                answers.append("B")
                mouse = False
            elif mouse == True and isPointInsideRect(position[0], position[1], press[7]):
                answers.append("C")
                mouse = False
            elif mouse == True and isPointInsideRect(position[0], position[1], press[8]):
                answers.append("D")
                mouse = False
            elif mouse == True and isPointInsideRect(position[0], position[1], press[9]):
                answers.append("E")
                mouse = False
    
    
    
            if len(answers)<=0:
                window.fill((0,0,0)) 
                window.blit(back[0], back[1])
                #buttons
                window.blit(press[0], press[5])
                window.blit(press[1], press[6])
                window.blit(press[2], press[7])
                window.blit(press[3], press[8])
                window.blit(press[4], press[9])
                #title
                window.blit(text[0], (180,25))
                #Question
                window.blit(text[1], (440,150))
                #answers below
                window.blit(text[2], (460,180))
                window.blit(text[3], (460,220))
                window.blit(text[4], (460,260))
                window.blit(text[5], (460,300))
                window.blit(text[6], (460,340))
    
            elif len(answers)==1:
    
                window.fill((0,0,0)) 
                window.blit(back[0], back[1])
                #buttons
                window.blit(press[0], press[5])
                window.blit(press[1], press[6])
                window.blit(press[2], press[7])
                window.blit(press[3], press[8])
                window.blit(press[4], press[9])
                #title
                window.blit(text[0], (180,25))
                #Question
                window.blit(text[7], (440,150))
                #answers below
                window.blit(text[8], (460,180))
                window.blit(text[9], (460,220))
                window.blit(text[10], (460,260))
                window.blit(text[11], (460,300))
                window.blit(text[12], (460,340))
    
            elif len(answers)==2:
    
                window.fill((0,0,0)) 
                window.blit(back[0], back[1])
                #buttons
                window.blit(press[0], press[5])
                window.blit(press[1], press[6])
                window.blit(press[2], press[7])
                window.blit(press[3], press[8])
                window.blit(press[4], press[9])
                #title
                window.blit(text[0], (180,25))
                #Question
                window.blit(text[13], (440,150))
                #answers below
                window.blit(text[14], (460,180))
                window.blit(text[15], (460,220))
                window.blit(text[16], (460,260))
                window.blit(text[17], (460,300))
                window.blit(text[18], (460,340))
    
            elif len(answers)==3:
    
                window.fill((0,0,0)) 
                window.blit(back[0], back[1])
                #buttons
                window.blit(press[0], press[5])
                window.blit(press[1], press[6])
                window.blit(press[2], press[7])
                window.blit(press[3], press[8])
                window.blit(press[4], press[9])
                #title
                window.blit(text[0], (180,25))
                #Question
                window.blit(text[19], (440,150))
                #answers below
                window.blit(text[20], (460,180))
                window.blit(text[21], (460,220))
                window.blit(text[22], (460,260))
                window.blit(text[23], (460,300))
                window.blit(text[24], (460,340))
    
            elif len(answers)==4:
    
                window.fill((0,0,0)) 
                window.blit(back[0], back[1])
                #buttons
                window.blit(press[0], press[5])
                window.blit(press[1], press[6])
                window.blit(press[2], press[7])
                window.blit(press[3], press[8])
                window.blit(press[4], press[9])
                #title
                window.blit(text[0], (180,25))
                #Question
                window.blit(text[25], (440,150))
                #answers below
                window.blit(text[26], (460,180))
                window.blit(text[27], (460,220))
                window.blit(text[28], (460,260))
                window.blit(text[29], (460,300))
                window.blit(text[30], (460,340))
    
            elif len(answers)==5:
    
                window.fill((0,0,0)) 
                window.blit(back[0], back[1])
                #buttons
                window.blit(press[0], press[5])
                window.blit(press[1], press[6])
                window.blit(press[2], press[7])
                window.blit(press[3], press[8])
                window.blit(press[4], press[9])
                #title
                window.blit(text[0], (180,25))
                #Question
                window.blit(text[31], (440,150))
                #answers below
                window.blit(text[32], (460,180))
                window.blit(text[33], (460,220))
                window.blit(text[34], (460,260))
                window.blit(text[35], (460,300))
                window.blit(text[36], (460,340))
    
            elif len(answers)==6:
                finalanswers = answers.list
                    print finalanswers
    
                pygame.quit()
    
    ###????????????????########--i'm also looking to put the answers into a list
    ##??????????##-------- how would the -if statments- look if i were to give an answer based on how many a's were chosen
                #--- or b's,c's,d's
    
    
    
            pygame.display.flip()
    
        elif screen == True:
            pass 
    #-------END-------
    

Edited 4 Years Ago by pyTony: title spelling

As I can not run your code without the icons, I can not answer your questions, I for now only offer this clean up of your functions (untested), even I think their action should be reconsidered.

#-----function definitions-----
def font():
    basicFont = pygame.font.SysFont(None, 50)
    questionFont = pygame.font.SysFont(None, 30)
    startcolor = (255,255,255)
    text = basicFont.render('Thematic Apperception Test', True, startcolor)
    questioncolor = (50,55,25)
    return [basicFont.render(t, True, questioncolor) for t in (
            "1) Who are these people?",
            "A Husband and wife",
            "A businessman and his mistress",
            "A murderer and his victim"
            "A doctor and his patient",
            "I don't know",

            "2) What are they feeling?",
            "Happy and/or tired",
            "Incomplete and/or unhappy",
            "Sad and/or lost",
            "Accomplished and/or healthy",
            "I don't know",

            "3) What are they thinking?",
            "What they are doing tomorrow",
            "how they cant wait to meet again",
            "how to cover up a mistake",
            "how to fix a problem",
            "I don't know",

            "4) What are they hoping for?",
            "To have a nice day"
            "To stop living a lie",
            "That this will be covered up",
            "That it was successful",
            "I don't know",

            "5) What led to this situation?",
            "A willing vacation",
            "An urge to run away",
            "A hateful relationship",
            "A call for help",
            "I don't know",

            "6) What's the outcome?",
            "They return back home",
            "Split up and move on",
            "Panic and run",
            "A new start",
            "I don't know")]

def startpage():
    background = pygame.Rect(0,0,800,533)
    startimage = pygame.image.load('background.gif')
    return [startimage, background]

def background():
    background = pygame.Rect(0,0,800,533)
    image = pygame.image.load('TAT_1.jpg')
    return [image, background]

def button():
    return  ([pygame.image.load(icon) for icon in ('a_Button.png',
                                                   'b_Button.png',
                                                   'c_Button.png',
                                                   'd_Button.png',
                                                   'e_Button.png')] +
              [pygame.Rect(435,pos,20,20) for pos in range(180, 341, 40)]) 

def isPointInsideRect(x, y, rect):
    return (rect.left < x < rect.right) and (rect.top < y < rect.bottom)

Edited 4 Years Ago by pyTony: triple comparison

Wow, thanks for the help. I am not sure if you want to take any more time but if you do, is there a way for me to share my graphics through this site? Thanks!

Thank you for the help. Any further information is appreciated. I uploaded the files.

Edited 4 Years Ago by lostlibearlarts: I don't think the original file attached so I did the each on their own

Attachments a_Button.png 3.38 KB background.gif 240.81 KB b_Button.png 3.34 KB c_Button.png 3.34 KB d_Button.png 3.3 KB e_Button.png 3.19 KB TAT_1.jpg 313.87 KB

I did not deal with the startscreen point but this is how I formatted your code finally:

#!/usr/bin/env python
#-----import modules-----
import sys, pygame, time, random
from collections import Counter

#-----function definitions-----
def font():
    basicFont = pygame.font.SysFont(None, 34)
    questionFont = pygame.font.SysFont(None, 28)
    startcolor = (255,255,255)
    questioncolor = (50,55,25)
    return (basicFont.render('Thematic Apperception Test', True, startcolor),
            [[questionFont.render(t, True, questioncolor) if answer else
              basicFont.render(t, True, questioncolor)
              for answer, t in enumerate(question)]

              for question in (
                ["1) Who are these people?",
                "A Husband and wife",
                "A businessman and his mistress",
                "A murderer and his victim",
                "A doctor and his patient",
                "I don't know"],

                ["2) What are they feeling?",
                "Happy and/or tired",
                "Incomplete and/or unhappy",
                "Sad and/or lost",
                "Accomplished and/or healthy",
                "I don't know"],

                ["3) What are they thinking?",
                "What they are doing tomorrow",
                "how they cant wait to meet again",
                "how to cover up a mistake",
                "how to fix a problem",
                "I don't know"],

                ["4) What are they hoping for?",
                "To have a nice day",
                "To stop living a lie",
                "That this will be covered up",
                "That it was successful",
                "I don't know"],

                ["5) What led to this situation?",
                "A willing vacation",
                "An urge to run away",
                "A hateful relationship",
                "A call for help",
                "I don't know" ],

                ["6) What's the outcome?",
                "They return back home",
                "Split up and move on",
                "Panic and run",
                "A new start",
                "I don't know"])
             ])

def startpage():
    background = pygame.Rect(0,0,800,533)
    startimage = pygame.image.load('background.gif')
    return [startimage, background]

def background():
    background = pygame.Rect(0,0,800,533)
    image = pygame.image.load('TAT_1.jpg')
    return [image, background]

def button():
    return  ([pygame.image.load(icon) for icon in
              ('a_Button.png', 'b_Button.png',
               'c_Button.png', 'd_Button.png', 'e_Button.png')],
              [pygame.Rect(430,pos,20,20) for pos in range(200, 400, 40)]) 

def isPointInsideRect(x, y, rect):
    return (rect.left < x < rect.right) and (rect.top < y < rect.bottom)


if __name__ == '__main__':
    pygame.init()
    window_size = 800, 533 
    window = pygame.display.set_mode((window_size))
    pygame.mouse.set_visible(True)
    pygame.display.set_caption('Thematic Apperception Test') 

    title, questions  = font()
    back  = background() 
    images, rectangles = button()
    start = startpage()

    answers = []
    question = iter(questions)
    text = next(question)
    prev = None
    q = False

    while not q:
        if text != prev:
            prev = text
            window.fill((0,0,0)) 
            window.blit(back[0], back[1])
            #buttons
            for image, rect in zip(images, rectangles):
                window.blit(image, rect)
            #title
            window.blit(title, (180,25))
            start = 160
            for t, pos in zip(text, range(start, 400, 40)):
                window.blit(t, (420 if pos==start else 460, pos))

        for event in pygame.event.get():
            if (event.type == pygame.QUIT) or (event.type==pygame.KEYDOWN and event.key==pygame.K_ESCAPE):
                q = True
                break
            elif (event.type == pygame.MOUSEBUTTONDOWN and event.button == 1):
                x, y = pygame.mouse.get_pos()
                mouse = True
                for pr, letter in zip(rectangles, 'ABCDE'):
                    if isPointInsideRect(x, y, pr):
                        answers.append(letter)
                        break
                else:
                    mouse = False

                if mouse:
                    #print answers[-1]
                    try:
                        text = next(question)
                    except StopIteration:
                        q = True
                        break
        pygame.display.flip()


    finalanswers = Counter(answers)
    for letter, count in sorted(finalanswers.items()):
        print letter, count, count*'*'
    pygame.quit()

Edited 4 Years Ago by pyTony: K_ESCAPE

If you consider thread solved, you can close thread as solved. It is also possible to give reputation for best posts by hovering over up arrow and typing your thanks/comment in the field opening or only like/dislike the article by clicking the up/down arrow

(I updated the code to have K_ESCAPE to quit not K_ENTER)

Edited 4 Years Ago by pyTony

This article has been dead for over six months. Start a new discussion instead.