In addition to importing tkinter, as I call the function, for example: _show (?, 'the title'), what do I put in the first variable that is image? Show an example if it's on the desktop.
The class PhotoImage
of tkinter
is used to show images in Label
s, Button
s, Canvas
and Text
.
The _show()
method is an internal method of the Image
object; It should not be called directly. One tip for this is that it starts with a _
; is an internal method, an implementation detail that is called by the PIL itself.
If you are creating a _show
method, you are trying to modify how PIL will display images, but you should not call this method directly.
Finally, the following is an example of using the PhotoImage
class, where an image is inserted into a text area tkinter.Text
:
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()