1,105,644 Community Members

KEYDOWN help

Member Avatar
wolfeater017
Light Poster
35 posts since Jul 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

[This is a really long code so im just going to put the traceback part in and where I think the problem is]

[def directions():
enter=0
nwscreen()
Font1 = pygame.font.SysFont('ActionIsShaded', 25)
d1 = basicFont.render('Directions',False,WHITE,BLACK)
d2 = Font1.render('Directions',False,WHITE,BLACK)
d3 = Font1.render('ALL ANSWERS MUST BE LOWERCASE',False,RED,BLACK)
d4 = Font1.render ('Press enter to continue...',False,GREEN,BLUE)
d1Rect = d1.get_rect()
d2Rect = d2.get_rect()
d3Rect = d3.get_rect()
d4Rect = d4.get_rect()
d1Rect.centerx = windowSurface.get_rect().centerx
d1Rect.centery = windowSurface.get_rect().centery-175
d2Rect.centerx = windowSurface.get_rect().centerx
d2Rect.centery = windowSurface.get_rect().centery-140
d3Rect.centerx = windowSurface.get_rect().centerx
d3Rect.centery = windowSurface.get_rect().centery-105
d4Rect.centerx = windowSurface.get_rect().centerx
d4Rect.centery = windowSurface.get_rect().centery-70
windowSurface.blit(d1,d1Rect)
windowSurface.blit(d2,d2Rect)
windowSurface.blit(d3,d3Rect)
windowSurface.blit(d4,d4Rect)
pygame.display.update()
while enter==0:
pygame.event.get()
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == KEYDOWN:
if event.key == K_KP_ENTER:
enter=enter+1
if event.key == K_ESCAPE:
pygame.quit()
sys.exit()
]


[Traceback (most recent call last):
File "C:\Python31\pytest.py", line 250, in <module>
directions()
File "C:\Python31\pytest.py", line 63, in directions
if event.type == KEYDOWN:
KeyboardInterrupt]


[Can anyone help me]

Member Avatar
pyTony
pyMod
6,104 posts since Apr 2010
Reputation Points: 818 [?]
Q&As Helped to Solve: 1,056 [?]
Skill Endorsements: 42 [?]
Moderator
Featured
 
0
 

code-tags, please.

(This is a really long code so im just going to put the traceback part in and where I think the problem is)

(Can anyone help me)

def directions():
    enter=0
    nwscreen()
    Font1 = pygame.font.SysFont('ActionIsShaded', 25)
    d1 = basicFont.render('Directions',False,WHITE,BLACK)
    d2 = Font1.render('Directions',False,WHITE,BLACK)
    d3 = Font1.render('ALL ANSWERS MUST BE LOWERCASE',False,RED,BLACK)
    d4 = Font1.render ('Press enter to continue...',False,GREEN,BLUE)
    d1Rect = d1.get_rect()
    d2Rect = d2.get_rect()
    d3Rect = d3.get_rect()
    d4Rect = d4.get_rect()
    d1Rect.centerx = windowSurface.get_rect().centerx
    d1Rect.centery = windowSurface.get_rect().centery-175
    d2Rect.centerx = windowSurface.get_rect().centerx
    d2Rect.centery = windowSurface.get_rect().centery-140
    d3Rect.centerx = windowSurface.get_rect().centerx
    d3Rect.centery = windowSurface.get_rect().centery-105
    d4Rect.centerx = windowSurface.get_rect().centerx
    d4Rect.centery = windowSurface.get_rect().centery-70
    windowSurface.blit(d1,d1Rect)
    windowSurface.blit(d2,d2Rect)
    windowSurface.blit(d3,d3Rect)
    windowSurface.blit(d4,d4Rect)
    pygame.display.update()
    while enter==0: 
        pygame.event.get() 
        if event.type == QUIT: 
            pygame.quit() 
            sys.exit() 
        if event.type == KEYDOWN: 
            if event.key == K_KP_ENTER: 
                enter=enter+1
            if event.key == K_ESCAPE: 
                pygame.quit() 
                sys.exit()

[Traceback (most recent call last):
  File "C:\Python31\pytest.py", line 250, in <module>
    directions()
  File "C:\Python31\pytest.py", line 63, in directions
    if event.type == KEYDOWN:
KeyboardInterrupt]
Member Avatar
pyTony
pyMod
6,104 posts since Apr 2010
Reputation Points: 818 [?]
Q&As Helped to Solve: 1,056 [?]
Skill Endorsements: 42 [?]
Moderator
Featured
 
0
 

Maybe you need to put code in

try.. except KeyboardInterrupt:

block somehow.

From this post of vegaseat: http://www.daniweb.com/forums/post1275991.html#post1275991
though I see the event taken like this:

keepGoing = True
    while keepGoing:
        #clock.tick(30)
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                keepGoing = False
You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: