Well I got a "small" problem with updating a label using Tkinter and PIL.
As soon as I press the cheese Button it should display foo2, but it just displays a white screen. Any suggestions?
Here is my code:
from PIL import Image as Im
from Tkinter import *
class MyWindow():
def __init__(self):
self.root = Tk()
self.maskPng = Im.open("foo.png")
self.maskPng.convert("RGBA")
self.maskPng.save("bar.gif", "GIF")
self.mask = PhotoImage(file = "bar.gif")
self.show = Label(self.root, image = self.mask).pack(side = "left")
self.speedBTN = Button(self.root, text = "cheese", command = self.speed).pack(side = "right")
self.changed = False
def speed(self):
self.speedImg = Im.open('foo2')
self.speedImg = self.speedImg.convert("RGBA")
# overlaying foo and foo2 -- it works I tested it
self.maskPng.paste(self.speedImg, (0,0), self.speedImg)
self.render()
def render(self):
self.mask = PhotoImage(self.speedImg)
self.show.configure(image = self.mask)
self.show.image = self.mask
def draw(self):
self.root.mainloop()
main = MyWindow()
main.root.mainloop()
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…