0

So I am having the strange issue with TKinter in python. I have a BitmapImage I checked the image before making it a ImageTk.BitmapImage object. I then tell the canvas object to create the image and then pack(). The image will only display if I put IMAGE.show() after, this throws an error cause you know ImageTk doesn't have a show.

ioFile = filedialog.askopenfilename()
hexData = PyUtils.openFile(ioFile)
binData = PyUtils.convertToBinary(hexData)
IMAGE = PyUtils.makeImage(binData)
IMAGE = ImageTk.BitmapImage(IMAGE, background='white')
binViewBox  = tk.Canvas(root, bg='light grey', width=60)
binViewBox.create_image((0,0), image=IMAGE, anchor='nw')
binViewBox.pack(anchor='nw', side=TOP, fill=BOTH, expand=True)

If I put the IMAGE.show() just under here, it will display in the canvas but throw and error, and I don't want to throw and except: pass in there.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
CaptObvious
  • 31
  • 1
  • 5

1 Answers1

0

Solved by passing a my image variable as a global. Which makes sense cause previously i was using classes to run the gui. And now no classes and since the image gets created inside the function, the image is getting collected after the function ends and the image isn't referenced. Still don't know why passing the image variable to the function didn't work but I guess it will remain a mystery.

CaptObvious
  • 31
  • 1
  • 5