Reputation:
I want to display an image in a popup. Does anyone know how to do it?
I tried image=(path) but it's not working ...
sg.popup_no_buttons('Text', title='Über uns', text_color=('#F7F6F2'), keep_on_top=True)
Currently:
Target:
Upvotes: 0
Views: 2804
Reputation: 13061
Confirm version of your tkinter not 8.5, especially for MacOS users, tkinter 8.5 does not support PNG image.
With option image
in sg.popup_no_buttons
, you can add image into popup.
Value of option image
str
for image filename (GIF or PNG), orbytes
for raw
or Base64
of image.import PySimpleGUI as sg
sg.popup_no_buttons('Text', title='Über uns', text_color=('#F7F6F2'), keep_on_top=True, image=sg.EMOJI_BASE64_HAPPY_IDEA)
sg.popup_no_buttons('Text', title='Über uns', text_color=('#F7F6F2'), keep_on_top=True, image="D:/1.png")
Image not aligned to center for sg.popup_no_buttons
, you may create a popup by yourself. Demo code as following,
from textwrap import wrap
import PySimpleGUI as sg
def popup(title, filename, message, width=70):
lines = list(map(lambda line:wrap(line, width=width), message.split('\n')))
height = sum(map(len, lines))
message = '\n'.join(map('\n'.join, lines))
layout = [
[sg.Image(filename=filename, expand_x=True)],
[sg.Text(message, size=(width, height), justification='center', expand_x=True)]
]
sg.Window(title, layout, keep_on_top=True, modal=True).read(close=2000)
popup('Über uns', 'D:/emoji.png', 'message')
message = """
Python is an easy to learn, powerful programming language.
It has efficient high-level data structures and a simple but effective approach to object-oriented programming.
Python’s elegant syntax and dynamic typing, together with its interpreted nature, make it an ideal language for scripting and rapid application development in many areas on most platforms.
""".strip()
popup('Über uns', 'D:/emoji.png', message)
Upvotes: 3