Tkinter Widget compound Parameter
This parameter can be used to define the position of the text in relation to the image when the image is co-located with the text. compound parameter can be the following values.
left
: the image is on the left.
right
: the image is on the right.
top
: the image is on top.
bottom
: the image is at the bottom.
center
: the text is overlaid on top of the image.
Tkinter Widget compound Parameter Example#1
When the image and text coexist, the image is on the left.
from tkinter import *
root = Tk()
root.title("apidemos.com")
label = Label(root,bitmap="hourglass",
compound="left",text="Welcome to apidemos.com") # Image on the left
label.pack() # Packaging and positioning components
root.mainloop()
Output:
Tkinter Widget compound Parameter Example#2
When the image and text coexist, the image is on top.
from tkinter import *
root = Tk()
root.title("apidemos.com")
label = Label(root,bitmap="hourglass",
compound="top",text="Welcome to apidemos.com") # Image on top
label.pack() # Packaging and positioning components
root.mainloop()
Output:
Tkinter Widget compound Parameter Example#3
When the image and text coexist, the text is overlaid on top of the image.
from tkinter import *
root = Tk()
root.title("apidemos.com")
label = Label(root,bitmap="hourglass",
compound="center",text="Welcome to apidemos.com") # Text overlay on top of the image
label.pack() # Packaging and positioning components
root.mainloop()
Output: