python – 为什么Photoimage放慢了?

前端之家收集整理的这篇文章主要介绍了python – 为什么Photoimage放慢了?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在操作photoimage对象时,使用:
  1. import tkinter as tk
  2.  
  3. img = tk.PhotoImage(file="myFile.gif")
  4. for x in range(0,1000):
  5. for y in range(0,1000):
  6. img.put("{red}",(x,y))

put操作需要很长时间.有更快的方法吗?

解决方法

使用边界框:
  1. from Tkinter import *
  2. root = Tk()
  3. label = Label(root)
  4. label.pack()
  5. img = PhotoImage(width=300,height=300)
  6. data = ("{red red red red blue blue blue blue}")
  7. img.put(data,to=(20,20,280,280))
  8. label.config(image=img)
  9. root.mainloop()

猜你在找的Python相关文章