【发布时间】:2016-10-14 13:14:07
【问题描述】:
我正在用 kivy 开发一个应用程序,目前正试图弄清楚为什么当我在 Python 中而不是在 .kv 文件中添加对象时,我可以得到一个要渲染的对象。
这很好用,渲染背景图像,上面有一个开关。
class LoginScreen(Screen):
def __init__(self,**kwargs):
super(LoginScreen, self).__init__(**kwargs)
self.layout = BoxLayout(orientation='vertical')
self.add_widget(self.layout)
self.layout.add_widget(defSwitch())
def on_touch_up(self,touch):
if self.collide_point(*touch.pos):
self.parent.current = 'data'
class defSwitch(Switch):
active = False
.kv 文件在哪里:
<LoginScreen>:
imgname: './images/' + 'login.jpg'
canvas.before:
Rectangle:
pos: self.pos
size: self.size
source: self.imgname
除了背景图像之外什么都不渲染:
class LoginScreen(Screen):
def on_touch_up(self,touch):
if self.collide_point(*touch.pos):
self.parent.current = 'data'
class defSwitch(Switch):
active = False
在这种情况下 .kv 文件的位置:
<LoginScreen>:
imgname: './images/' + 'login.jpg'
canvas.before:
Rectangle:
pos: self.pos
size: self.size
source: self.imgname
BoxLayout:
orientation: 'vertical'
defSwitch:
如果我将 .kv 文件中的 defSwitch: 替换为默认的 Switch 对象,则它可以正常渲染。为什么我不能使用自定义对象?
【问题讨论】:
标签: python python-2.7 kivy python-2.x kivy-language