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 JPG image from file
We can show a JPG image in a label widget by loading an image file.
1 2 3 4 5 6 7 8 91011121314151617
importtkinterastkfromtkinterimportttkfromPILimportImage,ImageTkmyfile=r"/images/pizza.JPG"root=tk.Tk()withImage.open(myfile)asimg:# Load the image into a format that Tk uses.tk_pizza=ImageTk.PhotoImage(img)lbl_test=ttk.Label(root,image=tk_pizza)lbl_test.pack()root.mainloop()
If we want to show the image and some text in the label, we need to use the compound setting.