Why is Photoimage put slow?

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?


Use a bounding box:

from Tkinter import *
root = Tk()
label = Label(root)
img = PhotoImage(width=300,height=300)
data = ("{red red red red blue blue blue blue}")
img.put(data, to=(20,20,280,280))

Try constructing a 2d array of colors and call put with that array as parameter.

Like this:

import tkinter as tk

img = tk.PhotoImage(file="myFile.gif")
# "#%02x%02x%02x" % (255,0,0) means 'red'
line = '{' + ' '.join(["#%02x%02x%02x" % (255,0,0)] * 1000) + '}'
img.put(' '.join([line] * 1000))

Need Your Help

Center a rotated Div

javascript jquery css geometry transform

I am working on a rotation of a child within parent. Parent is fixed width and height whereas child's width and height is dynamic.

Printing JasperReports using velocity template

java swing jasper-reports awt velocity

I am using velocity script engine , i have a xml template file which has a format of how the report should be printed . I am taking the inputs from a JTextarea and printing the pdf.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.