Reputation: 19
Screen:
Firstly,I have got problem with the white background of my Frame because it expand beyond LabelFrame. Secondly, I would like image to be in the middle of my Frame.
img = ImageTk.PhotoImage(Image.open(filename))
panel.image = img
panel.configure(image=img)
ImageFrame = LabelFrame(page1, text="Podgląd", height=200, width=300, background='white')
ImageFrame.grid(row=0, column=3, pady=10, padx=5)
panel = Label(ImageFrame)
panel.grid(row=0, column=0, sticky='NESW')
ImageFrame.grid_propagate(0)
Upvotes: 0
Views: 118
Reputation: 7176
The LabelFrame
contains the label, and you have given it the bg color "white". If you just want the interior to be white you can do that by inserting a new Frame
with bg='white'
, then put the image there.
Then; to place the image in the middle you have to tell grid()
to expand tha cell to fill the available area with columnconfigure()
and rowconfigure()
. See my example below:
from tkinter import *
page1 = Tk()
ImageFrame = LabelFrame(page1, text="Podgląd", height=200, width=300)
ImageFrame.grid(row=0, column=3, pady=10, padx=5)
ImageFrame.grid_propagate(0) # Stops geometry propagation
ImageFrame.columnconfigure(0, weight=1) # Expands cell to fill available space
ImageFrame.rowconfigure(0, weight=1) # --- " ---
whiteframe = Frame(ImageFrame, bg='white') # For white background
whiteframe.grid(row=0, column=0, sticky='nsew', padx=5, pady=5)
whiteframe.columnconfigure(0, weight=1) # Expands cell to fill available space
whiteframe.rowconfigure(0, weight=1) # --- " ---
img = PhotoImage(file='images/beer.png')
panel = Label(whiteframe, image=img)
panel.image = img
panel.grid(row=0, column=0)
page1.mainloop()
Upvotes: 1