element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Rocking Raspberry Pi
  • Challenges & Projects
  • Design Challenges
  • Rocking Raspberry Pi
  • More
  • Cancel
Rocking Raspberry Pi
Blog Made my first pygame application
  • Blog
  • Forum
  • Documents
  • Files
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: rushikesh988
  • Date Created: 25 Feb 2014 12:14 PM Date Created
  • Views 450 views
  • Likes 0 likes
  • Comments 0 comments
  • app
  • rocking_pi
  • pygame
Related
Recommended

Made my first pygame application

rushikesh988
rushikesh988
25 Feb 2014

Hi friends today I have made my first pygame application.I doesn't do much except for graphic rotation and changing the graphic when mouse is clicked.

 

Here is its execution video :

 

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

 

 

 

 

This is the code for the program:

 

import pygame, sys ,time
from pygame.locals import *

 

pygame.init()

 

FPS = 30 # frames per second setting
fpsClock = pygame.time.Clock()

 

# set up the window
DISPLAYSURF = pygame.display.set_mode((400, 300), 0, 32)
pygame.display.set_caption('Punch sam')

 

WHITE = (255, 255, 255)
catImg = pygame.image.load('sam.jpg')
sam_gaali=pygame.image.load('sam_gaali.jpg')
#pygame.mouse.set_cursor(rushi_hand,(self.x,self.y),self.mask,self.data)
catx = 10
caty = 10
direction = 'right'

 

while True: # the main game loop
    DISPLAYSURF.fill(WHITE)

 

    if direction == 'right':
        catx += 5
        if catx == 280:
            direction = 'down'
    elif direction == 'down':
        caty += 5
        if caty == 220:
            direction = 'left'
    elif direction == 'left':
        catx -= 5
        if catx == 10:
            direction = 'up'
    elif direction == 'up':
        caty -= 5
        if caty == 10:
            direction = 'right'

 

    DISPLAYSURF.blit(catImg, (catx, caty))

 

    if  pygame.mouse.get_pressed()[0]:
        pos=pygame.mouse.get_pos
        DISPLAYSURF.fill(WHITE)
        DISPLAYSURF.blit(sam_gaali, (catx, caty))
        pygame.display.flip()
        time.sleep(1)
       
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()

 

    pygame.display.update()
    fpsClock.tick(FPS)

 

 

 

 

 

I have made this program with python 2.7 and pygame 1.9.1.

 

I am also attaching its executable made from it using py2exe.

You can execute it using following steps:

1.go to dist folder after extracting the attachment.

2.execute punch_sam02.exe.

Attachments:
punch sam.zip
  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube