根据我绑定的内容弹出失败

  • 本文关键字:失败 绑定 kivy popup
  • 更新时间 :
  • 英文 :


下面是KIVY文件中我的动物选择器的相关部分:

AniPic@ANIMALPICKERid: arootlabelText:"imageSource:"animalCode:"AB"animalName:"GOGGA">

BoxLayout:
orientation: 'horizontal'
width: root.width
pos: 0,0
canvas.before:
RoundedRectangle:
pos: 5, 5
# the next two lines determine the position of the rectangle for the image
size: root.width-10,  root.height-10
source: root.imageSource
radius:[10]
PinButton:
id: _pin
on_release:
root.pin_action(root.labelText)
Label:
id: _label
text: root.labelText
width: root.width
color: (1, 1, 1, 1)
MapButton:
id: _map
on_release:
root.map_show(root.labelText)

#==========================================================================

AnimalWindow:

:id: animalid名称:"动物">

canvas.before:
Color:
rgba: 1, 1, 1, 1
Rectangle:
pos: self.pos
size: self.size
BoxLayout:
orientation: 'vertical'
Label:
id: choice
text: "Sightings"
color: 0, 0, 0, 1
size_hint_y: 0.05
canvas.before:
Color:
rgba: 0.5, 1, 0.5, 1
Rectangle:
pos: self.pos
size: self.size
ScrollView:
do_scroll_x: False
do_scroll_y: True
GridLayout:
size: (root.width, root.height)
cols: 1
rows: 9
padding: 10
spacing: 10
size_hint_x: None
size_hint_y: 9
height: self.minimum_height
row_default_height: 120
row_force_default: True
AniPic:
labelText: 'LION'
imageSource: 'images/lion_pic.jpg'
animalCode: 'LI'
AniPic:
labelText: 'CHEETAH'
imageSource: 'images/cheetah_pic.png'
animalCode: 'CH'

现在当我点击一个特定动物(CHEETA)的'PinButton'时,我让应用程序执行

def pin_it (_animal):Print ('aaaa', _animal)

和节目。

"aaaa级猎豹">

但是下面的弹出代码,我想要'确认'引脚动作,不显示弹出窗口,但崩溃:

类ANIMALPICKER(使用):Def pin_action(self, _animal):#准备确认你想锁定目标title_text = _animal + ' ' + 'SIGHTING'content_text = '确认目击?'

content_box = BoxLayout(orientation='vertical')
btn_box = BoxLayout(orientation='horizontal')
btn_box.height = 24
content_label = Label()
content_label.text = content_text
yes_btn = Button(text='Yes')
yes_btn.background_color = 0, 1, 0, 1
no_btn = Button(text='No')
no_btn.background_color = 1, 0, 0, 1
btn_box.add_widget(yes_btn)
btn_box.add_widget(no_btn)
content_box.add_widget(content_label)
content_box.add_widget(btn_box)
# Now confirm that you want to Pin the sighting
popup = Popup(title=title_text,
separator_height=4,
title_size='20sp',
content=content_box,
size_hint=(None, None),
size=(200, 240),
auto_dismiss=False)
# dismiss popup  and proceed to pin the sighting, on release of yes button
yes_btn.bind(on_press=pin_it(_animal))
# dismiss popup on release of the NO button
yes_btn.bind(on_release=popup.dismiss)
popup.open()

带有以下消息:

File "/home/sib/PycharmProjects/SpotMap/animalWindow.py",第66行,在pin_action .py&quotyes_btn.bind (on_press = pin_it (_animal))文件"kivy/_event.pyx",第444行,在kivy._event. eventdispatcher .bind中AssertionError: None is not callable

然而,当我绑定一个简单的'yes_btn.bind(on_press=dismiss)'而不是'yes_btn.bind(on_press=pin_it(_animal))'时,弹出窗口确实显示,弹出窗口在它所附加的按钮被按下时解散。

我已经82岁了,对Python, Kivy和OO的知识有限,我迫切需要帮助来完成这个应用程序。

绕道而行也会让我满意

多谢

我认为问题是pin_it(_animal)完成函数而不是引用函数对象。

from functools import partial
myfun = partial(pin_it, animal=_animal)
# this should be a function, not function()
yes_btn.bind(on_press=myfun)

最新更新