Why is Photoimage put slow?

前端 未结 3 716
伪装坚强ぢ
伪装坚强ぢ 2020-12-20 21:43

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):
         


        
3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-20 22:16

    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))
    

提交回复
热议问题