Python Kivy: How to add multiple widgets in a loop -


i relativly new python , totaly new kivy strugling solve simple task. need main screen 2 buttons: button1 , button2. when press button, second screen should appear showing again number of buttons. numbers of buttons on second screen dynamic can assume simplicity know it.

python code:

from kivy.app import app kivy.uix.boxlayout import boxlayout  buttons = {} buttons['button 1'] = ('a button 1', 'a button 2') buttons['button 2'] = ('b button 1', 'b button 2', 'b button 3')  class selectbutton(boxlayout):      def show_buttons(self, button):          self.clear_widgets() # guess need          #here question comes: how add button widgets buttons[button]?         #shall in loop in python code or in .kv file?         #for item in buttons[button]:         #    print (item)  class testapp(app):     pass  if __name__ == '__main__':     testapp().run() 

.kv file:

selectbutton:  <selectbutton>:     orientation: "vertical"     label:         size_hint_y: 0.15         text: "select button"     boxlayout:         button:             text: "button 1"             on_press: root.show_buttons(self.text)         button:             text: "button 2"             on_press: root.show_buttons(self.text) 

if truly dynamic should in python.

def show_buttons(self, button):      self.clear_widgets() # guess need       item in buttons[button]:         self.add_widget(button(text=item)) 

if not that dynamic, recommend create more screens , switch them when 1 of first buttons pressed using screenmanager


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -