Created
November 23, 2015 18:11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from kivy.app import App | |
from kivy.lang import Builder | |
from kivy.properties import ObjectProperty | |
from kivy.uix.dropdown import DropDown | |
from kivy.uix.screenmanager import ScreenManager, Screen | |
class WeatherDropDown(DropDown): | |
locw = ObjectProperty() | |
def on_select(self, x): | |
self.locw.dropbutton.text = x | |
class LocationAndWeatherScreen(Screen): | |
dropbutton = ObjectProperty() | |
def on_dropbutton(self, *args): | |
self.dropdown = WeatherDropDown(locw=self) | |
self.dropbutton.bind(on_release=self.dropdown.open) | |
class DropDownExampleApp(App): | |
def build(self): | |
self.manager = ScreenManager() | |
self.manager.add_widget(LocationAndWeatherScreen()) | |
return self.manager | |
Builder.load_string(""" | |
<WeatherDropDown>: | |
Button: | |
text: 'cold' | |
on_press: root.select('cold') | |
Button: | |
text: 'hot' | |
on_press: root.select('hot') | |
<LocationAndWeatherScreen>: | |
dropbutton: dropbutton | |
BoxLayout: | |
orientation: 'vertical' | |
Button: | |
id: dropbutton | |
text: 'Weather' | |
size_hint_y: 0.2 | |
Widget: | |
id: filler | |
""") | |
if __name__ == '__main__': | |
DropDownExampleApp().run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment