我写了一段代码用于实现一种Android锁定功能,但是每当我尝试使用ID获取特定的ClickableImage时,就会出现以下错误:
AttributeError: 'super' object has no attribute '__getattr__'
我花了数小时尝试寻找这个问题的解决方案,我查看了其他遇到相同问题的人的建议,他们告诉他们需要改变生成器的网站,因为它需要先调用ids属性或者类似的东西,但是每当我移动生成器时,都会出现"未定义的类"错误。有什么线索吗?
下面是我的代码:
from kivy.app import App
from kivy.config import Config
from kivy.lang import Builder
from kivy.graphics import Line
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.widget import Widget
from kivy.uix.image import Image
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.behaviors import ButtonBehavior
#Variables
cords = ()
bld = Builder.load_file('conf.kv')
class Manager(ScreenManager): pass
class Principal(Screen): pass
class ClickableImage(ButtonBehavior, Image):
def on_press(self):
self.source = 'button_press.png'
def on_release(self):
self.source = 'button.png'
self.ids.uno.source = 'button_press.png'
class canva(Widget):
def on_touch_down(self, touch):
global cords
with self.canvas:
touch.ud['line'] = Line(points=(touch.x, touch.y), width=1.5)
cords = (touch.x, touch.y)
def on_touch_move(self,touch):
global cords
touch.ud['line'].points = cords + (touch.x, touch.y)
def on_touch_up(self,touch):
self.canvas.clear()
class Api(App):
def build(self):
return bld
if __name__ == '__main__':
Api().run()
这是我的.kv文件:
# conf to file: test.py
<Manager>:
Principal:
<Principal>:
GridLayout:
size_hint_x: 0.5
size_hint_y: 0.6
width: self.minimum_width
cols: 3
ClickableImage:
id: 'uno'
size: 10,10
source: 'button.png'
allow_strech: True
ClickableImage:
id: 'dos'
size: 30,30
source: 'button.png'
allow_strech: True
canva:
self.parent.parent.ids
,因为self.ids
不存在。 - Peter Badida