By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,462 Members | 799 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,462 IT Pros & Developers. It's quick & easy.

How to display images on click via Python

P: 1
Hello, so I have this thing I'm making and where every time you click on a screen a new gif pops out. However, when I run it nothing appears on the new screen when I click.

This is what I have so far
Expand|Select|Wrap|Line Numbers
  1. import glob
  2. ypos = 0
  3. xpos = 0
  4. robotArmy = []
  5.  
  6. def setup():
  7.     global ypos
  8.     size(700,700)
  9.     ypos = height * 0.25
  10.     frameRate(12)
  11.     global animation1
  12.     animation1 = robots("./RobotGIF/robotprojects-",15) #ref from animatedspriteclass
  13.  
  14. def draw():
  15.     background(255)
  16.  
  17. class robots:
  18.     def __init__(self,imagePrefix,c): #from animatedSpriteClass
  19.         self.imageCount = c
  20.         self.images = []
  21.         self.frame = 0
  22.         print self.imageCount
  23.         for i in range(self.imageCount):
  24.             filename = imagePrefix + nf(i, 4) + ".gif"
  25.             self.images.append( loadImage(filename) )
  26.  
  27.     def draw(self,x,y): #ref animatedspriteclass
  28.         self.frame = (self.frame+1) % self.imageCount
  29.         image(self.images[self.frame], x, y)
  30.  
  31.     def getWidth(self):       
  32.         return self.images[0].width
  33.  
  34. def mousePressed():
  35.     robotArmy.append(animation1)
  36.  
  37.  
  38.  
  39.  
  40.  
Dec 17 '16 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 619
You have to use a program that displays images in order to see them on the screen. Like one of the GUI tookits or GIMP, or even a browser, etc. Also there is no screen to click on in the code you posted nor any callback for a screen click. You should be getting an error message on the following line because there is no function named image in the code.
Expand|Select|Wrap|Line Numbers
  1. image(self.images[self.frame], x, y) 
Dec 17 '16 #2

Post your reply

Sign in to post your reply or Sign up for a free account.