====>OK感谢它与b.bind(on_press=partial(self.choix_avatar,趋化蛋白))的合作-
我必须学习更多关于"callable“函数的知识...
关于Kivy中带有弹出事件的事件,我有一些不理解的地方。
在kivy 1.8.0版本中,我认为弹出窗口有一个bug
我已经创建了一个原始按钮: on_press =>创建弹出窗口在此弹出窗口中有许多按钮中的堆栈布局
当我按下原来的按钮时,on_press被传播到StackLayout的按钮!但是我的弹出窗口不是原始按钮的子部件!那为什么呢?一旦初始化,我就不能为我的按钮触发任何on_press。有什么想法吗?谢谢!R.T.
在.kv和.py中
<AvatarProfil>:
orientation:'vertical'
Button:
size:(60,60)
size_hint:(None,None)
on_press:root.changer_avatar()
background_normal:root.avatar
Label:
text:''
font_size:14
italic:True
halign:'left'
class AvatarProfil(BoxLayout):
auteur=StringProperty('')
avatar=StringProperty('test/interrogation.png')
def changer_avatar(self):
panel=PanelAvatar(w_avatar=self)
popup = Popup(title='Les Avatars à choisir',content=panel,size_hint=(None,None),size=(600,600))
popup.open()
def __init__(self, **kwargs):
super(AvatarProfil, self).__init__(**kwargs)
class PanelAvatar(StackLayout):
w_avatar=ObjectProperty(None)
def __init__(self, **kwargs):
self.spacing=(5,5)
super(PanelAvatar, self).__init__(**kwargs)
self.lavatars=[]
self.w_avatar=kwargs['w_avatar']
for root, dirs, files in os.walk('test/avatars resized', topdown=False):
for name in files:
chemin='test/avatars resized/'+name
b=Button(background_normal=chemin,on_press=self.choix_avatar(chemin),size_hint=(None,None))
self.add_widget(b)
def choix_avatar(self,file):
print ('choix de )%s'%(file))
self.w_avatar.avatar=file这是打印日志:(不需要按任何手动按钮!)
choix de )test/avatars resized/avatar (1).jpg
choix de )test/avatars resized/avatar (1).png
choix de )test/avatars resized/avatar (10).jpg
choix de )test/avatars resized/avatar (11).jpg
choix de )test/avatars resized/avatar (12).jpg
choix de )test/avatars resized/avatar (13).jpg
choix de )test/avatars resized/avatar (14).jpg
choix de )test/avatars resized/avatar (15).jpg
choix de )test/avatars resized/avatar (16).jpg
choix de )test/avatars resized/avatar (17).jpg
choix de )test/avatars resized/avatar (18).jpg
choix de )test/avatars resized/avatar (19).jpg
choix de )test/avatars resized/avatar (2).jpg
choix de )test/avatars resized/avatar (2).png
choix de )test/avatars resized/avatar (20).jpg
choix de )test/avatars resized/avatar (21).jpg
choix de )test/avatars resized/avatar (22).jpg
choix de )test/avatars resized/avatar (23).jpg
choix de )test/avatars resized/avatar (24).jpg
choix de )test/avatars resized/avatar (25).jpg
choix de )test/avatars resized/avatar (3).jpg
choix de )test/avatars resized/avatar (3).png
choix de )test/avatars resized/avatar (4).jpg
choix de )test/avatars resized/avatar (5).jpg
choix de )test/avatars resized/avatar (6).jpg
choix de )test/avatars resized/avatar (7).jpg
choix de )test/avatars resized/avatar (8).jpg
choix de )test/avatars resized/avatar (9).jpg发布于 2014-05-05 23:15:16
在这里,您调用的是choix_avatar(),而您只是想要绑定它。
b=Button(background_normal=chemin,on_press=self.choix_avatar(chemin),size_hint=(None,None))试试这个:
b=Button(background_normal=chemin, size_hint=(None,None))
b.bind(on_press=lambda *_: self.choix_avatar(chemin))https://stackoverflow.com/questions/23475855
复制相似问题