python - Resize image on mouse click in Pygame -


this code displays image , works:

import pygame  pygame.locals import *  pygame.init()  screen = pygame.display.set_mode((900,900))  lion = pygame.image.load("lion.jpg")  while true:    screen.blit(lion, (0,0))    pygame.display.update() 

i want able right click image adjust size. example:

pygame.event.get() buttonpress = pygame.mouse.get_pressed() press = pygame.key.get_pressed() screen.blit(lion,(100-(lion.get_width()/2, 100-(lion.get_height()/2)))) pygame.event.quit 

however, click on pygame window, stops responding , cannot it.

screen.blit() takes 2 arguments, surface , destination. seems trying use resize image. use pygame.transform.scale() takes surface , size arguments. example:

done = false while not done:     event in pygame.event.get():         if event.type == quit: #so can close window without crashing or giving error             done = true     pressed_buttons = pygame.mouse.get_pressed() #get tuple of boolean values pressed buttons     if pressed_buttons[2]: #if right mouse button down         adjusted_lion_image = pygame.transform.scale(lion, (lion.get_wdith() / 2, lion.get_height() / 2)) #set adjusted image image equal half size of original image      else: #if right mouse button not down         adjusted_lion_image = lion #set adjusted image lion image      screen.fill((0, 0, 0)) #fill screen black before draw make cleaner     screen.blit(adjusted_lion_image, (0, 0)) #blit adjusted image     pygame.display.update() #update screen  pygame.quit() #make sure outside of while loop. 

this should accomplish want. might want add .convert() after loading lion image convert image 1 pygame can use more readily:

lion = pygame.image.load("lion.jpg").convert() 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -