How to initialize this Tkinter Photoimage function?

Asked

Viewed 1,013 times

-1

inserir a descrição da imagem aqui

Besides importing Tkinter, what do I call the function, for example: _show(?, 'the title'), what do I put in the first variable that is image? Show any example if it is on the desktop.

  • Always give preference to sharing the code instead of an image, this enables other people to use your code as a basis, makes it easy to point out fixes and adaptations. Also, could you be a little clearer? I really don’t understand what you want.

2 answers

1


The class PhotoImage of tkinter is used to display images in Labels, Buttons, Canvas and Text.

The method _show() is an internal method of the object Image; It should not be called directly. A tip for this is that it starts with a _; is an internal method, a detail of implementation that is called by the PIL itself.

If you are creating a method _show, is trying to modify the way PIL will display images, but you should not call this method directly.

To finish follow an example of class use PhotoImage, where an image is inserted inside a text area tkinter.Text:

resultado

img = """
R0lGODlhIAAgAKIFAAAAAACt74xzUsbGxv/3AAAAAAAAAAAAACH/C05FVFNDQVBFMi4wAwHoAAAh+QQF
CgAHACwAAAAAIAAgAAADuBi63P4wyrmApbjam+nmkiCK0QdGwqCSj3k+asw2LhXfQrthtww4Ox4u9wp8
KKlVTnFy/VCjZUXjDEkZT6NJm11Ev1PmlssQ9ZRMcY2sSJ4HgqCTE3Sfl88a58vnG9VyfYJRf1xBAYOD
aYBjVyiLho0YeIySSItze5OQkVptmwoEoqIWox9xo6mqAqqmAKakca+tqay0paSztrS1vLgEp7O8oruq
v8AWssPErS6ry6PFuNPCxcO7CQAAIfkEBQYABwAsAQABABcAHQAAA4IYugwOLMr13ryhWiy1i0J4eZIw
DKNGKSc6VV3QRmRDAa7ibTe/qx7XbxgICXS7DIRXPP6QIKNT1YAoQq1BsrowZWtVq7e17UrPgjJ6/Wyu
pUo1J147YoZiDv46p8OKGASCBA6CGmmDiYqFD4ZpAIqRkIWJApGXkxoElpeLhoedBAkAADs=
"""
import tkinter as t

root = t.Tk()
img = t.PhotoImage(data=img)
text = t.Text(root)
text.insert(t.END, "Olá, aqui está a imagem:\n")
text.image_create(t.INSERT, image=img)
text.insert(t.END, "  Obrigado!")
text.pack()
root.mainloop()

0

Well, from what I understand, you want to put an image in your interface, if that’s right, this is a minimum code for you to add an image in your interface.

try:
   from tkinter import *
except:
   from Tkinter import *

tela = Tk()

imagem_blender = PhotoImage(file="low_poly.png")
foto = Label(tela, image=imagem_blender)
foto.grid(row=1,column=1)

tela.mainloop()

In this case, the image low_poly.png" is in the same folder as the script with that code, ok? Script mostrando a foto na interface gráfica

Browser other questions tagged

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