1 Replies - 1206 Views - Last Post: 07 July 2015 - 09:19 AM Rate Topic: -----

#1 slayerodd  Icon User is offline

  • D.I.C Head

Reputation: -4
  • View blog
  • Posts: 79
  • Joined: 10-May 15

'int' object has no attribute 'key'

Posted 07 July 2015 - 09:14 AM

My program is a piano with a guy opening his mouth each time i press and/or hold a button.

This is the code:
import pygame
import sys
import winsound
import time
pygame.init()

display_width = 400
display_height = 580

white = (255,255,255)
black = (  0,  0,  0)

gameDisplay = pygame.display.set_mode((display_width,display_height))
pygame.display.set_caption("Open The Mouth")
clock = pygame.time.Clock()

faceImg = pygame.image.load("face_shut.png")
faceOpenImg = pygame.image.load("face_open.png")
#faceDImg = pygame.image.load("")
#faceEImg = pygame.image.load("")
#faceFImg = pygame.image.load("")
gameDisplay.fill(white)
def text_objects(text, font):
    textSurface = font.render(text, True, black)
    return textSurface, textSurface.get_rect()
def message_display(text):
    title = pygame.font.Font("freesansbold.ttf",35)
    textSurf, textRect = text_objects(text,title)
    textRect.center = ((display_width/2),(350))
    gameDisplay.blit(textSurf,textRect)
    pygame.display.update()
def message_display2(text):
    tones = pygame.font.Font("freesansbold.ttf",20)
    textSurf, textRect = text_objects(text,tones)
    textRect.center = ((display_width/2),(400))
    gameDisplay.blit(textSurf,textRect)
    pygame.display.update()
def message_display3(text):
    tones = pygame.font.Font("freesansbold.ttf",20)
    textSurf, textRect = text_objects(text,tones)
    textRect.center = ((display_width/2),(420))
    gameDisplay.blit(textSurf,textRect)
    pygame.display.update()
def message_display4(text):
    tones = pygame.font.Font("freesansbold.ttf",20)
    textSurf, textRect = text_objects(text,tones)
    textRect.center = ((display_width/2),(440))
    gameDisplay.blit(textSurf,textRect)
    pygame.display.update()
def message_display5(text):
    tones = pygame.font.Font("freesansbold.ttf",20)
    textSurf, textRect = text_objects(text,tones)
    textRect.center = ((display_width/2),(460))
    gameDisplay.blit(textSurf,textRect)
    pygame.display.update()
def message_display6(text):
    tones = pygame.font.Font("freesansbold.ttf",20)
    textSurf, textRect = text_objects(text,tones)
    textRect.center = ((display_width/2),(480))
    gameDisplay.blit(textSurf,textRect)
    pygame.display.update()
def message_display7(text):
    tones = pygame.font.Font("freesansbold.ttf",20)
    textSurf, textRect = text_objects(text,tones)
    textRect.center = ((display_width/2),(500))
    gameDisplay.blit(textSurf,textRect)
    pygame.display.update()
def message_display8(text):
    tones = pygame.font.Font("freesansbold.ttf",20)
    textSurf, textRect = text_objects(text,tones)
    textRect.center = ((display_width/2),(520))
    gameDisplay.blit(textSurf,textRect)
    pygame.display.update()
def textTones():
    message_display2("Q = C3    A = C4    Z = C5")
    message_display3("W = D3    S = D4    X = D5")
    message_display4("E = E3    D = E4    C = E5")
    message_display5("R = F3    F = F4    V = F5")
    message_display6("T = G3    G = G4    B = G5")
    message_display7("Y = B3    H = B4    N = B5")
    message_display8("U = A3    J = A4    M = A5")
def textTitle():
    message_display("Tones")
def textGuide():
    textTitle()
    textTones()
def face(x,y):
    gameDisplay.blit(faceImg,(face_x,face_y))
def faceOpen(x,y):
    gameDisplay.blit(faceOpenImg,(faceOpen_x,faceOpen_y))
def faceCUpdate():
    face(face_x,face_y)
    pygame.display.update()
def faceOUpdate():
    faceOpen(faceOpen_x,faceOpen_y)
    pygame.display.update()
def toneC1():
    winsound.Beep(131,300)
def toneD1():
    winsound.Beep(147,300)
def toneE1():
    winsound.Beep(165,300)
def toneF1():
    winsound.Beep(175,300)
def toneG1():
    winsound.Beep(196,300)
def toneA1():
    winsound.Beep(220,300)
def toneB1():
    winsound.Beep(247,300)
def toneC2():
    winsound.Beep(262,300)
def toneD2():
    winsound.Beep(294,300)
def toneE2():
    winsound.Beep(330,300)
def toneF2():
    winsound.Beep(349,300)
def toneG2():
    winsound.Beep(392,300)
def toneA2():
    winsound.Beep(440,300)
def toneB2():
    winsound.Beep(494,300)
def toneC3():
    winsound.Beep(523,300)
def toneD3():
    winsound.Beep(587,300)
def toneE3():
    winsound.Beep(659,300)
def toneF3():
    winsound.Beep(698,300)
def toneG3():
    winsound.Beep(783,300)
def toneA3():
    winsound.Beep(880,300)
def toneB3():
    winsound.Beep(988,300)
def toneC4():
    winsound.Beep(1047,300)

faceOpen_x = (1)
faceOpen_y = (1)

face_x = (1)
face_y = (1)

programExit = False

face(face_x,face_y)
pygame.display.update()

while not programExit:
    pygame.key.get_pressed()
    textGuide()
    for event in pygame.key.get_pressed():
            if event.key == pygame.K_q:
                bool_q = True
                if bool_q:
                    faceOUpdate()
                    toneC1()
            if event.key == pygame.K_w:
                faceOUpdate()
                bool_w = True
                if bool_w:
                    faceOUpdate()
                    toneD1()
            if event.key == pygame.K_e:
                bool_e = True
                if bool_e:
                    faceOUpdate()
                    toneE1()
            if event.key == pygame.K_r:
                bool_r = True
                if bool_r:
                    faceOUpdate()
                    toneF1()
            if event.key == pygame.K_t:
                bool_t = True
                if bool_t:
                    faceOUpdate()
                    toneG1()
            if event.key == pygame.K_y:
                bool_y = True
                if bool_y:
                    faceOUpdate()
                    toneA1()
            if event.key == pygame.K_u:
                bool_u = True
                if bool_u:
                    faceOUpdate()
                    toneB1()
            if event.key == pygame.K_a:
                bool_a = True
                if bool_a:
                    faceOUpdate()
                    toneC2()
            elif event.key == pygame.K_s:
                bool_s = True
                if bool_s:
                    faceOUpdate()
                    toneD2()
            elif event.key == pygame.K_d:
                bool_d = True
                if bool_d:
                    faceOUpdate()
                    toneE2()
            elif event.key == pygame.K_f:
                bool_f = True
                if bool_f:
                    faceOUpdate()
                    toneF2()
            elif event.key == pygame.K_g:
                bool_g = True
                if bool_g:
                    faceOUpdate()
                    toneG2()
            elif event.key == pygame.K_h:
                bool_h = True
                if bool_h:
                    faceOUpdate()
                    toneA2()
            elif event.key == pygame.K_j:
                bool_j = True
                if bool_j:
                    faceOUpdate()
                    toneB2()
            elif event.key == pygame.K_z:
                bool_z = True
                if bool_z:
                    faceOUpdate()
                    toneC3()
            elif event.key == pygame.K_x:
                bool_x = True
                if bool_x:
                    faceOUpdate()
                    toneD3()
            elif event.key == pygame.K_c:
                bool_c = True
                if bool_c:
                    faceOUpdate()
                    toneE3()
            elif event.key == pygame.K_v:
                bool_v = True
                if bool_v:
                    faceOUpdate()
                    toneF3()
            elif event.key == pygame.K_b:
                bool_b = True
                if bool_b:
                    faceOUpdate()
                    toneG3()
            elif event.key == pygame.K_n:
                bool_n = True
                if bool_n:
                    faceOUpdate()
                    toneA3()
            elif event.key == pygame.K_m:
                faceOUpdate()
                toneB3()
        
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            programExit = True
        if event.type == pygame.KEYUP:
            if event.key == pygame.K_q:
                bool_q = False
            if event.key == pygame.K_w:
                bool_w = False
            if event.key == pygame.K_e:
                bool_e = False
            if event.key == pygame.K_r:
                bool_r = False
            if event.key == pygame.K_t:
                bool_t = False
            if event.key == pygame.K_y:
                bool_y = False
            if event.key == pygame.K_u:
                bool_u = False
            if event.key == pygame.K_a:
                bool_a = False
            if event.key == pygame.K_s:
                bool_s = False
            if event.key == pygame.K_d:
                bool_d = False
            if event.key == pygame.K_f:
                bool_f = False
            if event.key == pygame.K_g:
                bool_g = False
            if event.key == pygame.K_h:
                bool_h = False
            if event.key == pygame.K_j:
                bool_j = False
            if event.key == pygame.K_z:
                bool_z = False
            if event.key == pygame.K_x:
                bool_x = False
            if event.key == pygame.K_c:
                bool_c = False
            if event.key == pygame.K_v:
                bool_v = False
            if event.key == pygame.K_b:
                bool_b = False
            if event.key == pygame.K_n:
                bool_n = False
            if event.key == pygame.K_m:
                bool_m = False
    clock.tick(60)
pygame.quit()
quit()




And this is the error:
Traceback (most recent call last):
  File "C:\Python34\program\Open the mouth\otm.py", line 157, in <module>
    if event.key == pygame.K_q:
AttributeError: 'int' object has no attribute 'key'


Is This A Good Question/Topic? 0
  • +

Replies To: 'int' object has no attribute 'key'

#2 xclite  Icon User is offline

  • I wrote you an code
  • member icon


Reputation: 1253
  • View blog
  • Posts: 4,043
  • Joined: 12-May 09

Re: 'int' object has no attribute 'key'

Posted 07 July 2015 - 09:19 AM

event is an int object. Why do you think it should have an attribute called key?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1