Hi,
The app I'm working on needs to pass a variable set by a checkbox in the KV file back to the main Python program. The relevant section of the KV file is:
<SelectGenre>:
GridLayout:
cols: 2
Label:
text:'Fantasy'
CheckBox:
group: 'genre_group'
on_active: root.fantasy_genre(*args)
#:set genre 'fantasy'
Label:
text:'Sci-Fi'
CheckBox:
group: 'genre_group'
on_active: root.scifi_genre(*args)
#:set genre 'scifi'
Label:
text:'Cyberpunk'
CheckBox:
group: 'genre_group'
on_active: root.cyberpunk_genre(*args)
#:set genre 'cyberpunk'
Label:
text:'Wild West'
CheckBox:
group: 'genre_group'
on_active: root.wildwest_genre(*args)
#:set genre 'wildwest'
Label:
text:'Horror'
CheckBox:
group: 'genre_group'
on_active: root.horror_genre(*args)
#:set genre 'horror'
Button:
text:'Back'
on_press: root.manager.current = 'welcome'
Button:
text:'Next'
# on_press: root.manager.current = 'race'
on_press: root.choose_race_screen(genre)
I want to pass the variable for the chosen genre into the following Python function:
class SelectGenre(Screen):
# pass
#self.manager.genre = ''
def choose_race_screen(self,args):
print (self)
print (args)
print (*args)
race_display = args
print ("Race display =", race_display)
if race_display == 'fantasy':
sm.current = 'race_fantasy'
if race_display == 'scifi':
sm.current = 'race_scifi'
if race_display == 'cyberpunk':
sm.current = 'race_cyberpunk'
if race_display == 'wildwest':
sm.current = 'race_wildwest'
if race_display == 'horror':
sm.current = 'race_horror'
The idea being, if a scifi genre is chosen, the races appropriate to that genre will be displayed next. What's happening is that no matter which genre I select, it always ends up as "horror".
Now, I think variables set with the #:set construct in the KV file are treated as global variables and that (presumably) the last option in the <SelectGenre> screen overrides all the others. Is this correct?
So the question is: how do I set a local variable in the KV file which can be successfully passed to the choose_race_screen function?
Please let me know if any further information is needed.
Regards,
Colin Brett