Форум сайта python.su
Привет,
создадим канвас и кнопку:
import tkinter as tk class CanvasMain(tk.Frame): photos = {} id = {} def __init__(self, root=None): super(CanvasMain, self).__init__() self.canvas = tk.Canvas(width=500, height=500, bg='#aa9d93', bd=2, relief="solid") self.canvas.pack() self.button = tk.Button(text='Create pic', cursor = 'hand2', bd = 4, bg = 'grey', fg='white', relief='raised', font=('Comic Sans MS', 12, 'bold'), command=self.make_pic) self.button.pack(fill='x') def make_pic(self): self.photos['pic'] = tk.PhotoImage(file = 'numbers\\PythonPowered.gif') self.id['id_pic'] = self.canvas.create_image(12, 12, image = self.photos['pic'], anchor = 'nw') self.button.config(text='Delete picture', command=self.del_pic) print(self.canvas.find_all()) def del_pic(self): self.canvas.delete(self.id['id_pic']) self.photos.pop('pic') self.id.pop('id_pic') self.button.config(text='Create pic', command=self.make_pic) print(self.canvas.find_all()) if __name__ == '__main__': CanvasMain() tk.mainloop()
Отредактировано WoMax (Авг. 29, 2014 23:30:28)
Прикреплённый файлы:
example.zip (2,2 KБ)
Офлайн
что удалось найти в сети:
http://python.6.x6.nabble.com/Memory-leak-with-tkinter-canvas-itemconfigure-td1975033.html
Офлайн