I'm currently doing a school project and I can't use .kv files; so I have to do it through normal python. So, I'm converting my previous .kv file, but I'm unsure on how to create multiple screens and add buttons in normal python. Any help is greatly appreciated.
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen, FadeTransition
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout
#App windows
class MainMenu(Screen, Button, BoxLayout):
# def __init__(self, **kwargs):
# super(MainMenu, self).__init__(**kwargs)
menu_s = Screen(name = 'main')
layout = BoxLayout(orientaion = 'vertical')
slider_mode = Button(text = 'Slider Mode')
code_mode = Button(text = 'Code Mode')
settings = Button(text = 'Settings')
menu_s.add_widget(slider_mode)
menu_s.add_widget(code_mode)
menu_s.add_widget(settings)
class SliderMode(Screen):
slider_s = Screen(name = 'slider_m')
layout = BoxLayout(orientaion = 'vertical')
menu = Button(text = 'Menu')
slider_s.add_widget(menu)
WindowManager = ScreenManager()
WindowManager.add_widget(MainMenu())
WindowManager.add_widget(SliderMode())
#The app class
class MyMain(App):
def build(self):
return WindowManager
#Runs the App
if __name__ == '__main__':
MyMain().run()
The above code is what I've done so far; but when it's run, it gives this error:
TypeError: object.__init__() takes exactly one argument (the instance to initialize)
This is the .kv file below I'm trying to convert:
WindowManager:
MainMenu:
SliderMode:
<MainMenu>:
name: 'main'
BoxLayout:
orientation: 'vertical'
cols: 1
Button:
text: 'Slider Mode'
size_hint: 0.3, 0.3
pos_hint: {'x':0.35}
on_release:
app.root.current = 'slider_m'
Button:
text: 'Code Mode'
size_hint: 0.3, 0.3
pos_hint: {'x':0.35}
on_release:
app.root.current = 'code_m'
Button:
text: 'Settings'
size_hint: 0.3, 0.3
pos_hint: {'x':0.35}
on_release:
app.root.current = 'setting_m'
<SliderMode>:
name: 'slider_m'
FloatLayout:
Button:
text: 'Menu'
size_hint: 0.15, 0.15
pos_hint: {'x':0.0, 'y': 0.0}
on_release:
app.root.current = 'main'