Binding 'esc' in Kivy with screen management done in the kv file
up vote
0
down vote
favorite
I want to bind the esc key so i can switch screens on android back button press.
My understanding is that I have done screen management through the kv file and it has caused me trouble getting the online binding examples (that use management done in the py file) to work.
This is what I have:
weather.kv
ScreenManager:
id: screen_manager
SearchScreen:
id: search_screen
name: 'SearchScreen'
manager: screen_manager
ForecastScreen:
id: forecast_screen
name: 'ForecastScreen'
manager: screen_manager
<SearchScreen>:
<ForecastScreen>:
Then in the main.py
class SearchScreen(Screen):
location = StringProperty('No location')
def set_location(self, address):
self.location = str(address)
self.manager.current = "ForecastScreen"
class ForecastScreen(Screen):
#code
sm=Builder.load_file('weather.kv')
class WeatherApp(App):
def build(self):
Window.bind(on_keyboard=self.on_key)
return sm
def on_key(self, window, key, *args):
if key == 27: # the esc key
if self.screen_manager.current_screen.name == "SearchScreen":
return False # exit the app from this page
elif self.screen_manager.current_screen.name == "ForecastScreen":
self.screen_manager.current = "SearchScreen"
return True
if __name__ == "__main__":
WeatherApp().run()
Let me know if you need to see more of my code. Button based screen switching works but the self.screen_manager says that screen_manager is not part of the self object.
android kivy kivy-language
add a comment |
up vote
0
down vote
favorite
I want to bind the esc key so i can switch screens on android back button press.
My understanding is that I have done screen management through the kv file and it has caused me trouble getting the online binding examples (that use management done in the py file) to work.
This is what I have:
weather.kv
ScreenManager:
id: screen_manager
SearchScreen:
id: search_screen
name: 'SearchScreen'
manager: screen_manager
ForecastScreen:
id: forecast_screen
name: 'ForecastScreen'
manager: screen_manager
<SearchScreen>:
<ForecastScreen>:
Then in the main.py
class SearchScreen(Screen):
location = StringProperty('No location')
def set_location(self, address):
self.location = str(address)
self.manager.current = "ForecastScreen"
class ForecastScreen(Screen):
#code
sm=Builder.load_file('weather.kv')
class WeatherApp(App):
def build(self):
Window.bind(on_keyboard=self.on_key)
return sm
def on_key(self, window, key, *args):
if key == 27: # the esc key
if self.screen_manager.current_screen.name == "SearchScreen":
return False # exit the app from this page
elif self.screen_manager.current_screen.name == "ForecastScreen":
self.screen_manager.current = "SearchScreen"
return True
if __name__ == "__main__":
WeatherApp().run()
Let me know if you need to see more of my code. Button based screen switching works but the self.screen_manager says that screen_manager is not part of the self object.
android kivy kivy-language
Thescreen_manager
is not a field of anApp
, but it is available in that method (sm
that you referenced inbuild
).
– John Anderson
Nov 11 at 1:18
ahhh yes I see now that I can modify the current screen though 'sm.current=', thank you @JohnAnderson
– learningCurve
Nov 11 at 3:09
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I want to bind the esc key so i can switch screens on android back button press.
My understanding is that I have done screen management through the kv file and it has caused me trouble getting the online binding examples (that use management done in the py file) to work.
This is what I have:
weather.kv
ScreenManager:
id: screen_manager
SearchScreen:
id: search_screen
name: 'SearchScreen'
manager: screen_manager
ForecastScreen:
id: forecast_screen
name: 'ForecastScreen'
manager: screen_manager
<SearchScreen>:
<ForecastScreen>:
Then in the main.py
class SearchScreen(Screen):
location = StringProperty('No location')
def set_location(self, address):
self.location = str(address)
self.manager.current = "ForecastScreen"
class ForecastScreen(Screen):
#code
sm=Builder.load_file('weather.kv')
class WeatherApp(App):
def build(self):
Window.bind(on_keyboard=self.on_key)
return sm
def on_key(self, window, key, *args):
if key == 27: # the esc key
if self.screen_manager.current_screen.name == "SearchScreen":
return False # exit the app from this page
elif self.screen_manager.current_screen.name == "ForecastScreen":
self.screen_manager.current = "SearchScreen"
return True
if __name__ == "__main__":
WeatherApp().run()
Let me know if you need to see more of my code. Button based screen switching works but the self.screen_manager says that screen_manager is not part of the self object.
android kivy kivy-language
I want to bind the esc key so i can switch screens on android back button press.
My understanding is that I have done screen management through the kv file and it has caused me trouble getting the online binding examples (that use management done in the py file) to work.
This is what I have:
weather.kv
ScreenManager:
id: screen_manager
SearchScreen:
id: search_screen
name: 'SearchScreen'
manager: screen_manager
ForecastScreen:
id: forecast_screen
name: 'ForecastScreen'
manager: screen_manager
<SearchScreen>:
<ForecastScreen>:
Then in the main.py
class SearchScreen(Screen):
location = StringProperty('No location')
def set_location(self, address):
self.location = str(address)
self.manager.current = "ForecastScreen"
class ForecastScreen(Screen):
#code
sm=Builder.load_file('weather.kv')
class WeatherApp(App):
def build(self):
Window.bind(on_keyboard=self.on_key)
return sm
def on_key(self, window, key, *args):
if key == 27: # the esc key
if self.screen_manager.current_screen.name == "SearchScreen":
return False # exit the app from this page
elif self.screen_manager.current_screen.name == "ForecastScreen":
self.screen_manager.current = "SearchScreen"
return True
if __name__ == "__main__":
WeatherApp().run()
Let me know if you need to see more of my code. Button based screen switching works but the self.screen_manager says that screen_manager is not part of the self object.
android kivy kivy-language
android kivy kivy-language
asked Nov 10 at 23:10
learningCurve
477
477
Thescreen_manager
is not a field of anApp
, but it is available in that method (sm
that you referenced inbuild
).
– John Anderson
Nov 11 at 1:18
ahhh yes I see now that I can modify the current screen though 'sm.current=', thank you @JohnAnderson
– learningCurve
Nov 11 at 3:09
add a comment |
Thescreen_manager
is not a field of anApp
, but it is available in that method (sm
that you referenced inbuild
).
– John Anderson
Nov 11 at 1:18
ahhh yes I see now that I can modify the current screen though 'sm.current=', thank you @JohnAnderson
– learningCurve
Nov 11 at 3:09
The
screen_manager
is not a field of an App
, but it is available in that method (sm
that you referenced in build
).– John Anderson
Nov 11 at 1:18
The
screen_manager
is not a field of an App
, but it is available in that method (sm
that you referenced in build
).– John Anderson
Nov 11 at 1:18
ahhh yes I see now that I can modify the current screen though 'sm.current=', thank you @JohnAnderson
– learningCurve
Nov 11 at 3:09
ahhh yes I see now that I can modify the current screen though 'sm.current=', thank you @JohnAnderson
– learningCurve
Nov 11 at 3:09
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53244324%2fbinding-esc-in-kivy-with-screen-management-done-in-the-kv-file%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
The
screen_manager
is not a field of anApp
, but it is available in that method (sm
that you referenced inbuild
).– John Anderson
Nov 11 at 1:18
ahhh yes I see now that I can modify the current screen though 'sm.current=', thank you @JohnAnderson
– learningCurve
Nov 11 at 3:09