Tkinter не рисует изображение на холсте из другого метода.
Пример 1 работает, пример 2 не работает. Может кто-нибудь объяснить, почему?
пример 1
def init_gui(self):
window = tkinter.Tk()
self.canvas = tkinter.Canvas(self.window, width=1000, height=500)
photo = PIL.ImageTk.PhotoImage(image=PIL.Image.fromarray(self.img))
self.canvas.create_image(0, 0, image=photo, anchor=tkinter.NW)
self.canvas.pack()
window.mainloop()
pass
пример 2
def init_gui(self):
window = tkinter.Tk()
self.canvas = tkinter.Canvas(self.window, width=1000, height=500)
self._draw_img() # the exact same code, only in another method
window.mainloop()
pass
def _draw_img(self):
photo = PIL.ImageTk.PhotoImage(image=PIL.Image.fromarray(self.img))
self.canvas.create_image(0, 0, image=photo, anchor=tkinter.NW)
self.canvas.pack()
pass