这是我的文件
<GetAccount>:
Button:
id: refresh
ang: 0
background_normal: 'static/refresh.png'
size_hint: None, None
size: sp(50), sp(50)
pos_hint: {'center_y': .96, 'center_x': .8}
on_press: root.clean()
canvas.before:
Rotate:
angle: self.ang
origin: self.center
python代码中的一些逻辑和动态内容
class GetAccount(FloatLayout):
keyandnick = ObjectProperty(KeyAndNick())
account = ObjectProperty(Account())
def __init__(self, **kargs):
super(GetAccount, self).__init__(**kargs)
layout = StackLayout(size_hint_y=None)
layout.bind(minimum_height=layout.setter('height'))
nicks = self.keyandnick.get_nicks()
for nick in nicks:
layout.add_widget(Button(text=str(nick[0]), size_hint_y=None, height=sp(60), on_press=self.ask_for_key))
scroll = ScrollView(size_hint=(1, .9), bar_width=sp(5), bar_inactive_color=[.7, .7, .7, .5])
scroll.add_widget(layout)
self.add_widget(scroll)
def ask_for_key(self, obj):
self.clear_widgets()
self.account_name = obj.text
boxlayout = BoxLayout(size_hint=(1, .4), orientation='vertical', pos_hint={'center_y': .5})
self.key = TextInput(pos_hint={'center_y': .5}, hint_text='Key', font_size=sp(30), password=True)
boxlayout.add_widget(self.key)
boxlayout.add_widget(Button(text='Get Account', font_size=sp(30), on_press=self.get_account))
boxlayout.add_widget(Button(text='Delete Account', pos_hint={'center_x': .5}, font_size=sp(30), on_press=self.delete_account))
popup = Popup(title=self.account_name, content=boxlayout, size_hint=(1, .7))
popup.bind(on_dismiss=self.clear)
popup.open()
def get_account(self, obj):
if self.keyandnick.check_key(self.key.text):
self.clear_widgets()
boxlayout = BoxLayout(orientation='vertical', size_hint=(1, .6), pos_hint={'center_y': .5})
_account = self.account.get_account(self.account_name)
a = True
for data in _account:
if a:
boxlayout.add_widget(Label(text=data, font_size=sp(30), bold=True, underline=True))
a = False
else:
boxlayout.add_widget(Label(text=data, font_size=sp(20)))
popup = Popup(title=self.account_name, content=boxlayout, size_hint=(1, .7))
popup.open()
else:
self.key.background_color = [0, 0, 255, 0.3]
def clean(self):
animation = Animation(ang=360)
animation.start(self.ids.refresh)
animation.bind(on_complete=self.clear)
def clear(self, a, b):
self.clear_widgets()
self.add_widget(GetAccount())
def delete_account(self, obj):
if self.keyandnick.check_key(self.key.text):
self.account.delete_account(self.account_name)
self.keyandnick.del_nick(self.account_name)
else:
self.key.background_color = [0, 0, 255, 0.3]
当我按下有id的按钮时-
线程线程1中的异常:回溯(最近一次调用最后一次):
文件“/usr/lib/python3.5/threading.py”,第914行,在内部自引导中。run()文件“/usr/lib/python3.5/threading.py”,第862行,在run self中_target(*self.\u args,**self.\u kwargs)文件“/home/ubuntu/.py-3.5.2/lib/python3.5/site packages/kivy/input/providers/mtdev.py”,第197行,在thread\u run device=device(fn)文件“/home/ubuntu/.py-3.5.2/lib/python3.5/site packages/kivy/lib/lib/mtdev.py”中,第131行,在init self中_fd=操作系统。打开(文件名,os.O_NONBLOCK | os.O_RDONLY)权限错误:[Errno 13]权限被拒绝:'/dev/input/event6'
animation=animation(ang=360)animation。启动(self.ids.refresh)动画。绑定(on_complete=self.clear)动画结束。动画=动画(ang=360)动画。启动(self.ids.refresh)动画。绑定(on_complete=self.clear)动画结束。[INFO][Base
]正在退出应用程序。。。回溯(最近一次调用last):AccountMaintainerApp()中第146行的文件“main.py”。runTouchApp EventLoop中runTouchApp()文件“/home/ubuntu/.py-3.5.2/lib/python3.5/site packages/kivy/app.py”第824行中的“home/ubuntu/.py-3.5.2/lib/python3.5/site packages/kivy/base.py”第487行。窗mainloop()文件“/home/ubuntu/.py-3.5.2/lib/python3.5/site packages/kivy/core/window/window\u sdl2.py”,mainloop self中的第525行_mainloop()文件“/home/ubuntu/.py-3.5.2/lib/python3.5/site packages/kivy/core/window/window\u sdl2.py”,第290行,在mainloop事件循环中。idle()文件“/home/ubuntu/.py-3.5.2/lib/python3.5/site packages/kivy/base.py”,第327行,在空闲时钟中。勾选()文件“/home/ubuntu/.py-3.5.2/lib/python3.5/site packages/kivy/clock.py”,第483行,勾选self_进程事件()文件“/home/ubuntu/.py-3.5.2/lib/python3.5/site packages/kivy/clock.py”,第615行,在进程事件事件中。勾选(self.\u last.\u勾选,删除)文件“/home/ubuntu/.py-3.5.2/lib/python3.5/site packages/kivy/clock.py”,第374行,勾选ret=callbackback(self.\u dt)文件“/home/ubuntu/.py-3.5.2/lib/python3.5/site packages/kivy/animation.py”,第342行,勾选更新self。停止(小部件)文件“/home/ubuntu/.py-3.5.2/lib/python3.5/site packages/kivy/animation.py”,第213行,在stop self中。取消(小部件)文件“/home/ubuntu/.py-3.5.2/lib/python3.5/site packages/kivy/animation.py”,第222行,在cancel self中_小部件。kivy中第19行的pop(widget.uid,None)文件“kivy/weakproxy.pyx”。软弱的。软弱的。getattr(/tmp/pip-build-zy75v30v/kivy/kivy/weakproxy.c:1097)文件“kivy/weakproxy.pyx”,第15行,在kivy中。软弱的。软弱的。ref(/tmp/pip-build-zy75v30v/kivy/kivy/weakproxy.c:1004)引用错误:弱引用对象不再存在
编程指南»Kv语言
id是小部件的弱引用,而不是小部件本身。因此,存储id不足以防止小部件被垃圾收集。
要使小部件保持活动状态,必须保持对id刷新的直接引用。这是通过使用id.\uuuuu self\uuuuuuu或刷新来实现的__在这种情况下,自我保护。
<GetAccount>:
refresh: refresh.__self__
Button:
id: refresh
ang: 0
background_normal: 'static/refresh.png'
size_hint: None, None
size: sp(50), sp(50)
pos_hint: {'center_y': .96, 'center_x': .8}
on_press: root.clean()
canvas.before:
Rotate:
angle: self.ang
origin: self.center