Search code examples
pythontkinter

How to place a label after all the widgets? (tkinter)


I want to attach a link to my image but the label is coming over the text. How can I create a label so that it comes after the text.

self.text_widget is a Text object and I'm adding an image which is a label object and has self.text_widget as it's parent/master. I want this label to be placed after the text entered in the text widget but it's coming over it and covering those text as a result. This is my code:

global my_image,m2,m3 
my_image = PhotoImage(file="images\the-call4.gif") 
label1=Label(self.text_widget, image=my_image) 
label1.pack() 
label1.bind("<Button-1>", lambda e: callback("http://www.google.com"))

Solution

  • Here is the general idea. Insert your text first then apply the image.

    Make sure you insert a few line feeds at the end of text.

    imageName = "images\the-call4.gif"
    #  Suppose this is you text widget
    text = tk.Text( master, width = 80, height = 24 )
    text.pack( fill = 'both' )
    
    text.insert( '1.0', 'Your text goes here\n\n' )
    
    my_image = tk.PhotoImage( file = imageName ) 
    label1 = tk.Label( text, image = my_image )
    text.window_create( 'end', window = label1 )