Self.background = Label(self, image=self.background_image) Self.background_image = ImageTk.PhotoImage(self.image) This is example application that uses Pillow to resize image on the Label as the label changes size: from tkinter import *Ĭlass Example( Frame): def _init_( self, master, *pargs): Not sure if there is a way of doing this in tkinter? Or if perhaps I would write my own function that resizes the image according to the window size, however the image needs to resize relatively smoothly and quickly if the user resizes the window at any point. The centering functionality is already there, I just need the resize functionality.Ĭurrently what I have is: from tkinter import *īackground_image = PhotoImage(file= "Background.gif")īackground = Label(root, image=background_image, bd= 0) In a 400x900 window, the image does not resize, and centers itself horizontally.In a 500x400 window, the image resizes to 500x500, and still centers itself vertically.In a 800x400 window, the image does not resize, and centers itself vertically.Is there a way of resizing the image so that if the largest of the width and height of the window is smaller than the image, the image is adjusted to that size, keeping aspect ratio. However when the window is smaller than the image in width and height, it puts the center of the image in the center of the window, so you don’t see the whole image, and it looks a little odd. The image is placed over the background, and if the window is wider than it is tall, the image centers itself in the middle over the black background, and it all looks very nice. I have a square background image, which fades to black around the edges, and then the main window has a black background. Trying to set up a background for my tkinter window. I don’t have your 4 Dry Out Logo.png logo image, but here’s how things looked after clicking the button while running on my system using a substitute image. Self.TitleLabel = Label(ameFit, text="e-Rental Portal", bg="blue", Self.lbl_image = small_img # Save reference to local image object. Small_img = img.subsample(2) # Smaller copy of global img size 50% # img = PhotoImage(file='4 Dry Out Logo.png') Self.Btn = Button(master, text="Water Damage Equipment", command=self.MenuWin, Self.titleLabel = Label(master, text="4 Dry Out e-Rental", bg="blue", fg="white", Image_filename = '8-ball.png' # I don't have your image. You can find some documentation on it, copy(), zoom(), as well as the other methods of the Photoimage class has by using Python’s built-in help system from the Python console: i.e. ![]() ![]() I see Bryan Oakley has already posted an answer your question, but I’ll supplement it with my own, which also fixes several other problems (some related to this) I noticed in your code and shows how to resize the image without using PIL using the subsample() method Bryan mentioned in a comment under your related question that was closed as a duplicate. ![]() ![]() Self.TitleLabel = Label(ameFit, text="e-Rental Portal", bg="blue", fg="white", font=("Arial Black",15)).pack() Photo = PhotoImage(file='4 Dry Out Logo.png') Self.Btn = Button(master, text="Water Damage Equipment", command=self.MenuWin, bg="navy", fg="white", font=("Roboto")).pack() Self.titleLabel = Label(master, text="4 Dry Out e-Rental", bg="blue", fg="white", font=("Arial Black", 20)) Img=PhotoImage(file='4 Dry Out Logo.png')
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |