如何通过Python点击显示图像

你好,我有一个我正在制作的东西,每次你点击屏幕,就会弹出一个新的gif。然而,当我运行它时,当我单击时,新屏幕上什么也没有显示。
这就是我到目前为止所拥有的

选择 | 换行 | 行号
  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.  
# 回答1


你必须使用一个显示图像的程序才能在屏幕上看到它们。比如一个图形用户界面工具或GIMP,甚至一个浏览器等等。在你发布的代码中也没有可以点击的屏幕,也没有任何屏幕点击的回调。您应该会在以下行收到一条错误消息,因为代码中没有名为IMAGE的函数。

选择 | 换行 | 行号
  1. image(self.images[self.frame], x, y) 

标签: python

添加新评论