Reputation: 641
I can't seem to get my popup to open because it is not 'defined'. Everything is passed from the Python to the Kivy language (because it's just easier for me to keep track of everything) and this is the problem spot in question.
<StoryScreen>:
name: "story"
BoxLayout:
id: storyScreen
Popup:
id: "popup"
title: "Settings"
on_parent:
if self.parent == storyScreen: self.parent.remove_widget(self)
GridLayout:
cols: 2
Accordion:
orientation: "vertical"
AccordionItem:
title: "Main Character"
size_hint:.9, 0.10
pos_hint: {'x':0.05, 'y':0.85}
Label:
id: first
text: "First Name"
AccordionItem:
title: "Love Interest"
size_hint: .9, 0.10
pos_hint: {'x':0.05, 'y':0.70}
Button:
text: "What's up"
Button:
text: "Press to open popup"
on_release: popup.open()
Label:
text: "This is a label"
My traceback error reads:
File "/Applications/Kivy.app/Contents/Resources/kivy/kivy/lang.py", line 1299, in custom_callback
exec(__kvlang__.co_value, idmap)
File "./story.kv", line 54, in <module>
on_release: popup.open()
NameError: name 'popup' is not defined
And even when I tried adding to Python
class popup(Popup):
pass
It still throws a definition error. Help?
Upvotes: 0
Views: 854
Reputation: 14824
kv language id
s are Python identifiers. You can't call a Python variable "popup"
(because of the quotes), so it's the same with kv. Try using id: popup
instead of id: "popup"
.
Upvotes: 0
Reputation: 29488
Well...popup really isn't defined, that's the problem.
You need to get an instance of the popup class (e.g. Popup()
), so you can run something like Popup().open()
.
That's just for the kivy popup class, for your own subclass you must import it into the kv scope, e.g. #:import Yourpopupname main.Yourpopupname
, then you can do Yourpopupname().open()
. I say yourpopupname
rather than your chosen popup
because this is a really bad name to choose, it is confusing since it's the same up to capitalisation as kivy's Popup. Also, you should generally use widget names starting with an upper case letter because kv language relies on this to identify them.
Upvotes: 0