0

I'm trying to make a program that lets you select a BMP image and display it. When I press the button and select an image, the window is resized to accommodate the imageLabel, but the image stays invisible.

What can I do to make it visible?

import tkinter as tk
from PIL import ImageTk, Image
from tkinter import filedialog

class space():
    def changeLabel(self):
        self.chosenFileName = filedialog.askopenfilename(initialdir="C:/Users/gregl/.spyder-py3/projects/image processing/test images", title="Select A File", filetypes=[("BMP Files", "*.bmp")])
        self.label["text"] = self.chosenFileName
        self.imageLabel["image"] = ImageTk.PhotoImage(Image.open(self.chosenFileName))
        self.imageLabel.pack()
        
    def __init__(self):
        self.root = tk.Tk()
        self.label = tk.Label(self.root)
        self.label["text"] = "Please select an image!"
        self.imageLabel = tk.Label(self.root, image=None)
        self.button = tk.Button(self.root, text="Choose image", command=lambda: self.changeLabel())
        self.button.pack()
        self.label.pack()
        self.root.mainloop()


space()
TheLizzard
  • 6,523
  • 2
  • 10
  • 26
Greg Koc
  • 72
  • 6

0 Answers0