Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Getting _tkinter.TclError: image pyimage1 doesn't exist when trying to call image_viewer module I have a launcher application that is suppose to call functions from separate

Getting _tkinter.TclError: image pyimage1 doesn't exist when trying to call image_viewer module

I have a launcher application that is suppose to call functions from separate modules using a button. I have a module named "image_viewer" containing a class function that is suppose to display an image after clicking a button. The image_viewer function works fine in its original module but when I try to call it from my Launcher module I receive the error "_tkinter.TclError: image "pyimage1" doesn't exist". I have included my code for the launcher and image_viewer modules for your reference below.

**image_viewer module:**

from PIL import ImageTk, Image import tkinter as tk class ImageViewer: def __init__(self, root, image_filename): self.root = root self.image_filename = image_filename self.root.title('ImageViewer') self.root.geometry('400x350') self.canvas = tk.Canvas(self.root, width=300, height=300) self.canvas.place(x=10, y=10) self.btnView = tk.Button(text='View', command=self.view_image) self.btnView.place(x=20, y=265) self.btnClose = tk.Button(text='close', command=lambda:[self.destroy(), self.clear()]) self.btnClose.place(x=65, y=265) def view_image(self): self.img = ImageTk.PhotoImage(Image.open(self.image_filename)) # Keep ref to image. self.canvas.create_image(20, 20, anchor=tk.NW, image=self.img) def destroy(self): self.root.destroy() def clear(self): self.btnClose.destroy() self.btnView.destroy() def main(image_filename): root = tk.Tk() ImageViewer(root, image_filename) root.mainloop() if __name__ == '__main__': main('../raw/as.png') **Launcher module:**

from audioplayer import audioplayer from texteditor import editor from imageviewer import image_viewer import tkinter as tk class Launcher: def __init__(self, win): self.root = win self.root.title('Launcher') self.root.geometry('400x350') self.btnEditor = tk.Button(text='Editor', command=self.editor, padx=10) self.btnEditor.pack(side=tk.LEFT) self.btnEditor.place(x=5, y=315) self.btnAudio = tk.Button(text='AudioPlayer', command=self.audioplayer, padx=10) self.btnAudio.pack(side=tk.LEFT) self.btnAudio.place(x=75, y=315) self.btnImage = tk.Button(text='ImageViewer', command=self.imageviewer, padx=10) self.btnImage.pack(side=tk.LEFT) self.btnImage.place(x=178, y=315) self.quit_button = tk.Button(text = "Quit", command=self.quit, padx=10) self.quit_button.pack(side=tk.LEFT) self.quit_button.place(x=340, y=315) def editor(self): editor.main() def audioplayer(self): audioplayer.main() def imageviewer(self): image_viewer.main('../raw/as.png') def quit(self): self.root.destroy() def main(): root = tk.Tk() Launcher(root) root.mainloop() if __name__ == '__main__': main()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Carlos Coronel, Steven Morris

14th Edition

978-0357673034

More Books

Students also viewed these Databases questions