ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> pygame-users
pygame-users
[pygame] Drawing a box with the mouse
by Eric Hunter other posts by this author
Jul 28 2007 8:29PM messages near this date
Re: [pygame] OpenGL Build Trouble | Re: [pygame] Drawing a box with the mouse
I've been working at this for some time now and I can't figure out what the
problem is. What i'm trying to do is when the mouse is clicked, it saves the
mouse x,y then when the mouse clicks again at a different location it saves
the new mouse x,y then transforms.scale a image of a box with those
coordinates. For some reason I can't get the second mouse x,y to show up.
Thanks in advance!

import pygame
from pygame.locals import *
import sys


pygame.init ()
screen = pygame.display.set_mode((500,350)).convert()
background = pygame.Surface(screen.get_size())
#background = background.convert()
background.fill((250, 250, 250))
yellow_block = pygame.image.load("yellow_box.gif")
screen.blit(background, (0, 0))
pygame.display.flip()

while True:
    for event in pygame.event.get():
        if event.type == pygame.MOUSEBUTTONDOWN:
            mouseX1, mouseY1 = pygame.mouse.get_pos ()
            print "Mouse 1", mouseX1, mouseY1
            clear = pygame.event.clear()
            while not pygame.MOUSEBUTTONDOWN:
                mouseX2, mouseY2 = pygame.mouse.get_pos()
                print "Mouse 2", mouseX2, mouseY2
                box_resize = ((mouseX2 - mouseX1) + 1), ((mouseY2 - mouseY1)
+ 1)
                yellow_block = pygame.transform.scale(yellow_block,
box_resize)
                background.blit(yellow_block, (mouseX1, mouseY1))
                screen.blit(background, (0, 0))
                pygame.display.update(yellow_block)

            #box_size = 100, 100
            #yellow_block = pygame.transform.scale(yellow_block, box_size)
            #background.blit(yellow_block, (mouseX1, mouseY1))

            #screen.blit(background, (0, 0))
            #pygame.display.flip()
        elif event.type == pygame.QUIT:
            sys.exit()


Eric Hunter
hunter.eric1@gmail.com
Thread:
Eric Hunter
Ethan Glasser-Camp
Ian Mallett
Ian Mallett
Ian Mallett

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved