I'm working on getting an option menu that is the same throughout all of my screens. The option menu is a Popup with a few options. When the popup is called, it doesn't save the inputs. When the Switch button is changed to inactive, it defaults back to active after the user closes and reopens the popup.
How do I save the user's inputs?
from kivy.app import App
from kivy.core.window import Window
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.popup import Popup
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.switch import Switch
Builder.load_string('''
<OptionMenu@Button>:
text: "Option Menu"
size_hint_y: .3
on_press:
app.option_menu_function()
<BoxLayout@BoxLayout>:
orientation: "vertical"
<HomeScreen>:
BoxLayout:
OptionMenu:
Label:
text: "Home Screen"
Button:
text: "Next Screen >"
on_release:
app.root.current = "screen1"
<Screen1>:
BoxLayout:
OptionMenu:
Label:
text: "Screen 2"
Button:
text: "Next Screen >"
on_release:
app.root.current = "homescreen"
<SM>:
name: "sm"
id: sm
HomeScreen:
name: "homescreen"
id: hs
Screen1:
name: "screen1"
id: s1
''')
class HomeScreen(Screen):
pass
class Screen1(Screen):
pass
class SM(ScreenManager):
pass
class MyApp(App):
def build(self):
global sm
sm = SM()
return sm
def option_menu_function(self):
box = BoxLayout(orientation = "horizontal")
switch = Switch(active = True)
popup = Popup(content = box, auto_dismiss = True, size_hint = (None, None), size = (Window.width/1.5, Window.width/1.5))
box.add_widget(switch)
popup.open()
if __name__ == "__main__":
MyApp().run()