我不知道为什么,但当我想改变我的弹出背景(我用python创建的,不是kivy),我会改变整个屏幕的背景,除了我的实际弹出。我的代码看起来像这样(分解很多):
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.popup import Popup
from kivy.uix.label import Label
from kivy.core.window import Window
class BoxL(BoxLayout):
def chooseFile(self):
self.chosePop = Popup()
self.chosePop.title = 'My Popup'
choseBox = BoxLayout()
choseBoxLabel = Label()
choseBoxLabel.text = 'Any Text'
choseBox.add_widget(choseBoxLabel)
self.chosePop.content = choseBox
self.chosePop.background_normal = ''
self.chosePop.background_color = 0.5, 0.75, 0, 0.75
self.chosePop.open()
class GUI(App):
def build(self):
self.title = 'MyApp'
return BoxL()
if __name__ == '__main__':
GUI().run()
我也试过这样做:
from kivy.graphics import Rectangle, Color
class BoxL(BoxLayout):
def chooseFile(self):
with self.chosePop.canvas:
Color(0, 0.5, 0.75, 0.75)
Rectangle(pos=choseBox.pos, size=choseBox.size)
#Rectangle(pos=self.chosePop.pos, size=self.chosePop.size) #this brings the correct size but at a wrong position, and the original popup background doesnt get changed either)
在}{}更难,因为{}的开发人员没有任何方法访问{}背景色
Popup
中,您看到的大部分是Labels
的背景。一个Label
是title
,另一个是你的ChooseBoxLabel
。通过使用带有kv
规则的自定义类为背景创建彩色Rectangle
,可以轻松调整ChooseBoxLabel
的背景色。{以下是您可以做的一些事情的示例:
在上面的代码中,
MyBoxLayout
自定义类提供了一个蓝色背景,只有当其中的Label
没有填充Layout
时,该背景才可见。kv
中的Label
规则为title
和chooseBoxLabel
提供背景色,但它将影响App
中的每个Label
事实上,我觉得这很简单。我的回答使问题复杂化了。我相信您只需添加以下行:
就在您创建
Popup
之后相关问题 更多 >
编程相关推荐