We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,605 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

KEYDOWN help

[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]

2
Contributors
2
Replies
36 Minutes
Discussion Span
2 Years Ago
Last Updated
3
Views
wolfeater017
Light Poster
35 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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]
pyTony
pyMod
Moderator
6,299 posts since Apr 2010
Reputation Points: 879
Solved Threads: 984
Skill Endorsements: 26

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
pyTony
pyMod
Moderator
6,299 posts since Apr 2010
Reputation Points: 879
Solved Threads: 984
Skill Endorsements: 26

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0615 seconds using 2.69MB