【发布时间】:2020-07-27 06:36:22
【问题描述】:
我不知道为什么,但是当我想改变我的弹出背景(我在 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)
【问题讨论】:
标签: python popup kivy background-color