Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is Photoimage put slow?

Tags:

python

tkinter

When manipulating PhotoImage objects with:

import tkinter as tk

img = tk.PhotoImage(file="myFile.gif")
for x in range(0,1000):
  for y in range(0,1000):
    img.put("{red}", (x, y))

The put operation takes a very long time. Is there a faster method of doing this?

like image 683
HaskellElephant Avatar asked May 02 '12 16:05

HaskellElephant


1 Answers

Use a bounding box:

from Tkinter import *
root = Tk()
label = Label(root)
label.pack()
img = PhotoImage(width=300,height=300)
data = ("{red red red red blue blue blue blue}")
img.put(data, to=(20,20,280,280))
label.config(image=img)
root.mainloop()
like image 53
noob oddy Avatar answered Sep 29 '22 08:09

noob oddy