Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tkinter photoimage constructor

Tags:

python

tkinter

I am forced to use the plain PhotoImage class, since I had too many troubles installing PIL on the osx machine I use - I can live with it, resorting to use just GIF files.

Trouble is, there's a place where I really need to create a new image of a given color, size: just a simple colored square. There is some way to do it, à la Image.new('RGB', size, color) ?

like image 402
alessandro Avatar asked Mar 06 '26 15:03

alessandro


1 Answers

from Tkinter import * #from tkinter

root = Tk()
i = PhotoImage(width=100, height=100)
l = Label(root, image=i)
l.pack()
i.put("{red}", to=(4,6,80,80))
root.update()
root.after(3000)
i.put("{blue}", to=(4,6,80,80))
root.mainloop()
like image 177
noob oddy Avatar answered Mar 09 '26 03:03

noob oddy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!