Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 3rd, 2013, 07:23 AM
Sam115 Sam115 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2013
Posts: 3 Sam115 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 25 m 42 sec
Reputation Power: 0
Pygame Help

Hi guys,
I'm very new to python and pygame and need a bit of help.

I know how to make my program exit with KEYUP or KEYDOWN. I just want to know this: how would I write it so that I could exit the program with any other key, like the "A" key for example.

Thank You

Reply With Quote
  #2  
Old March 3rd, 2013, 08:26 AM
Dietrich's Avatar
Dietrich Dietrich is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 482 Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Days 22 h 23 m 21 sec
Reputation Power: 63
The "a" key would be simpler.
__________________
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25

Reply With Quote
  #3  
Old March 3rd, 2013, 08:46 AM
Sam115 Sam115 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2013
Posts: 3 Sam115 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 25 m 42 sec
Reputation Power: 0
Yea, that is what I meant. I just want to know how I would be able to close the program by pressing one specific key.

Reply With Quote
  #4  
Old March 3rd, 2013, 09:19 AM
Dietrich's Avatar
Dietrich Dietrich is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 482 Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Days 22 h 23 m 21 sec
Reputation Power: 63
I modified a typical example I had ...
Code:
''' pg_exit1.py
exploring best ways to exit a Pygame loop
for key codes see:
http://www.pygame.org/docs/ref/key.html
'''

import pygame as pg

pg.init()

# create a 300 x 300 pixel display window
# the default background is black
win = pg.display.set_mode((300, 300))
# optional title bar caption
pg.display.set_caption('A Pygame Circle')

# draw a white circle
white = (255, 255, 255)
center = (150, 150)
radius = 100
# width of 0 (default) fills the circle
# otherwise it is thickness of outline
width = 0
# draw.circle(Surface, color, pos, radius, width)
# width of 0 (default) fills the circle
pg.draw.circle(win, white, center, radius, width)

# update the display window to show the drawing
pg.display.flip()

# event loop and exit conditions using
# specified key or display window x click
while True:
    for event in pg.event.get():
        if event.type == pg.QUIT:
            # most reliable exit on x click
            pg.quit()
            raise SystemExit
        elif event.type == pg.KEYDOWN:
            # optional exit with "a" key
            if event.key == pg.K_a:
                pg.quit()
                raise SystemExit

Reply With Quote
  #5  
Old March 3rd, 2013, 10:17 AM
Sam115 Sam115 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2013
Posts: 3 Sam115 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 25 m 42 sec
Reputation Power: 0
Thank You

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Pygame Help

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap