Skip to content

Instantly share code, notes, and snippets.

Created November 23, 2015 18:11
Show Gist options
  • Save anonymous/c23f8626e04dd4f4a4f0 to your computer and use it in GitHub Desktop.
Save anonymous/c23f8626e04dd4f4a4f0 to your computer and use it in GitHub Desktop.
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