格式化 Kivy 弹出窗口以消除弹出背景

2022-01-15 00:00:00 python kivy

问题描述

我们在 kivy 应用程序中使用图像作为弹出窗口,但似乎无法让弹出窗口的背景适合图像的大小.生成的弹出窗口中的图像在图像的左侧、顶部和右侧周围带有深灰色边框.有人可以帮我们消除弹出窗口的背景,以便只看到图像和半透明滤镜吗?

we're using an image as a popup in our kivy app but can't seem to get the popup's background to fit the size of the image. The resulting popup has the image with a dark gray border around the left side, top, and right side of the image. Can someone help us eliminate the popup's background so that only the image and the semi-transparent filter are visible?

Main.py 代码:

Main.py code:

popup = Popup(title="",
                  content=Image(source='img/popup'),
                  auto_dismiss=True,
                  size_hint=(None, None),
                  size=(400, 146),
                  separator_height=0
                  )

谢谢


解决方案

如果你没有标题,也许一个简单的 ModalView 会更适合你的目的.

If you don't have a title, maybe a simple ModalView would better fit your purposes.

无论哪种方式,背景都由 backgroundbackground_color 属性控制.要完全摆脱它,设置 popup.background_color=(0, 0, 0, 0) (即透明)可能是最简单的.

Either way, the background is controlled by the background and background_color properties. To get rid of it entirely, it's probably simplest to set popup.background_color=(0, 0, 0, 0) (i.e. transparent).

相关文章