I don't have ads on this website. Donations help keep this site going.
If you find tkinter-snippets.com useful, please donate any amount you feel comfortable with.
Visit https://ko-fi.com/jobinpy to donate. Thank you!
ttk.Label – Load PNG image from file
The Label widget can be used for displaying an image.
1 2 3 4 5 6 7 8 9101112131415161718
importtkinterastkfromtkinterimportttk,PhotoImage# Image file pathimg_pizza=r"images/pizza.png"# Load the image into a format that Tk can use.tk_pizza=PhotoImage(file=img_pizza)# Create and initialize the labellbl_greeting=ttk.Label(root,text="Some Text.",image=tk_pizza)lbl_greeting.pack()root.mainloop()
If we want to show the image and some text in the label, we need to use the compound setting.