Sunday 15 January 2012

python - tkinter images on canvas disappears -


I want to keep copies of the "master" image, which I select from the tk.Listbox on the canvas. The full program code here is such a big place, so I kept some parts of it. Import Import DIP Callback (Event) as Image, Image Import Importer Importing as Taxicor Import: label.master_image = ImageTk.PhotoImage (Image.open (path)) label.configure (image = label.master_image) def apply (): Canvas.copy_image = copy.copy (label.master_image) canvas.create_image (10,10, canvas.copy_image) Root = tk.Tk () frame = tk.frame (master = root) canvas = vaccine. Canvas (master = frames) listbox = tk.listbox (master = frames) listbox.insert (tk.END, * dircache.listdir ('./images')) listbox.bind (' & gt; ButtonRelease-1 & gt; ', Callback) label = tk.Label (master = frame) button = tk.Button (master = frame, text =' apply ', command = apply) canvas.pack () frame. Pop () listbox.pack () label.pack () button.pack () root.mainloop ()

But when I click on another menu point ("Apply "Not on the button), which means that label.master_image changes, the image disappears on the canvas.

Before using the change on the PS canvas, it is used for preview on the label.master_image label.

Keep in the context of the image copy.copy is not necessary.

canvas.copy_image = label.master_image

  image by PIL import, IMAGE tech import os deef callback Tinkinters (Event): IDX, = List box. Cessation () path = os.path.join ('images', listbox.get (idx)) label.master_image = ImageTk.PhotoImage (Image.open (path)) label.configure (image = label.master_image) def apply ( ): Canvas.copy_image = label.master_image canvas.create_image (10,10, image = canvas.copy_image) root = Tk.Tk () frame = tk.frame (master = root) canvas = vaccine. Canvas (master = frames) listbox = tk.Listbox (master = frames) listbox.insert (tk.END, * os.listdir ('images')) Listbox.bind ('& gt; ButtonRelease-1 & gt;', Callback) label = tk.Label (master = frame) button = vaccine. Button (master = frame, text = 'apply', command = apply) canvas pack () frame. Pack () listbox.pack () label.pack () button.pack () root.mainloop ()    

No comments:

Post a Comment