notsolowki
notsolowki

Reputation: 107

Tkinter image overlay

I have been going through examples on image overlay for tkinter with no success. I have a program that has a text entry widget and a bunch of button. I'm trying to figure out how I can overlay an image in the GUI window. It doesn't need to be transparent. Whats the most simple way to overlay an image in a tkinter window.

Here is how my window is set up:

class App(tk.Tk):
    def __init__(self, *args, **kwargs):
        tk.Tk.__init__(self, *args, **kwargs)
        self.P = tk.Text(self, borderwidth=0, height=1, width=5, font= ("italic",))  # textbox sixe
        self.P.configure(fg="red", bg="black", font=("italic", 39))
        self.P.place(x=1, y=1)
        self.P.insert(tk.END, label)
        self.T = tk.Text(self, borderwidth=0, height=2, width=5, font=( 
        "italic", 65))
        self.T.place(x=2, y=58)
        self.button7 = Button(self, text="Show Options", command=self.enableOptions, fg="blue", font="bold")
        self.button7.place(x=152, y=1)
        self.updateWidgets()

I need an example using this code to get a photo to overlay the GUI screen, I have all the image modules and PIL installed.

Upvotes: 0

Views: 1987

Answers (1)

Rohit HR
Rohit HR

Reputation: 36

You can use the following code to display image as background.

background_image=tk.PhotoImage(image_location_in your system)
background_label = tk.Label(parent, image=background_image)
background_label.place(x=0, y=0, relwidth=1, relheight=1)

Also note image must be in .gif format only.

Upvotes: 2

Related Questions