How do I import Python image with the Tkinter GUI?

Asked

Viewed 10,442 times

0

How to place an image in the Tkinter library widget?

  • 1

    Do you have any code where you want to use the image to show?

  • in reality is the basis for Tkinter

1 answer

2


The 'hello world' image on Tkinter is something like the following code:

import tkinter as tk
root = tk.Tk()

imagem = tk.PhotoImage(file="stack-overflow.png")
w = tk.Label(root, image=imagem)
w.imagem = imagem
w.pack()

root.mainloop()

Upshot:

resultado da execução do programa, mostrando imagem

P.S. A complete path to the image in Windows would look something like this:

imagem = tk.PhotoImage(file="c:/Users/Public/Pictures/stack-overflow.png")
  • But I can insert a photo from the pc gallery?

  • 1

    @Biancasan Yes, just put her full address.

  • 1

    thank you so much:-)

  • 1

    @Biancasan included at the end of the answer an example of full path to a file on the computer (need now switch to your case)

  • how I would adjust the image size ?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.