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)
确认tkinter的版本不是8.5,特别是对于MacOS用户,tkinter 8.5不支持PNG图像
使用
sg.popup_no_buttons
中的image
选项,您可以将图像添加到弹出窗口中选项
image
的值str
用于图像文件名(GIF或PNG),或bytes
用于图像的raw
或Base64
李>图像未与
sg.popup_no_buttons
的中心对齐,您可以自己创建一个弹出窗口。演示代码如下:相关问题 更多 >
编程相关推荐