我正在使用Python 2.7和kivy。我运行test.py
,并且直接从文件夹test.png
替换了click on press me
后,新图像就不会显示。有人可以告诉我如何刷新图像吗?
from kivy.app import App
from kivy.uix.popup import Popup
from kivy.uix.button import Button
from kivy.lang import Builder
Builder.load_string('''
#:kivy 1.10.0
<abc>:
background: 'test.png'
''')
class abc(Popup):
pass
class PopupApp(App):
title = 'Popup Demo'
def build(self):
self._popup = abc()
return Button(text="press me", on_press=self._popup.open)
PopupApp().run()
答案 0 :(得分:1)
使用弹出式窗口的on_open
事件刷新弹出式窗口背景的加载。
from kivy.app import App
from kivy.uix.popup import Popup
from kivy.uix.button import Button
from kivy.lang import Builder
Builder.load_string('''
#:kivy 1.11.0
<abc>:
title : "change title color"
title_color: 1, 0, 0, 1 # red title
size_hint: None, None
size: 400, 400
BoxLayout:
orientation: "vertical"
GridLayout:
cols: 1
Label:
bold: True
text: "make label bold"
color: 1, 0, 0, 1 # red color text
Label:
markup: True
text: "[b][color=008000]make[/color] label [color=3333ff]bold[/color][/b]"
''')
class abc(Popup):
def __init__(self, **kwargs):
super(abc, self).__init__(**kwargs)
self.i = 0
def on_open(self):
if self.i % 2 == 0:
self.background = 'DSC08518.JPG'
else:
self.background = 'yellow.png'
self.i += 1
class PopupApp(App):
title = 'Popup Demo'
def build(self):
self._popup = abc()
return Button(text="press me", on_release=self._popup.open)
PopupApp().run()