Search code examples
pythontkinterpycharm

How to pad the location for the image on the label?


How to pad the location for the image on the label?


I am working on project in which the image is basically the size of the label and some text that I want to show isn't visible...when I remove the image, the label text is shown. I have to pad the location for the image on the label.


Solution

  • The label automatically resizes to account for the size of the image, so what you can do is, use the compound option to move the image to whichever position you prefer.

    From a doc:

    If you would like the Label widget to display both text and a graphic (either a bitmap or an image), the compound option specifies the relative orientation of the graphic relative to the text. Values may be any of tk.LEFT, tk.RIGHT, tk.CENTER, tk.BOTTOM, or tk.TOP. For example, if you specify compound=BOTTOM, the graphic will be displayed below the text.

    So:

    Label(root,text='Image 1',image=img,compound='top').pack()