B
B
boda10062021-09-04 13:58:04
Kivy
boda1006, 2021-09-04 13:58:04

How to make in python kivy so that when you click on the buttons, completely different buttons appear?

It is necessary that when you press the button, other 5 buttons appear. How can this be implemented?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2021-09-17
@20PYTHON20

You create a function in the class of something like that, you prescribe the number of buttons there that you will need.
Further, in the main button , with which others will open, write the following:

button_open.bind  (on_press = *название функции без звездочек )

When pressed, the buttons will appear.
* MyApp.py file
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.screenmanager import ScreenManager , Screen

class MenuScreen(Screen) :
    def __init__(self,**kwargs) :
        super(MenuScreen,self).__init__(**kwargs)
        self.fl = BoxLayout(orientation = "vertical")
        #Кнопка на которую нужно нажать 
        self.but_open = Button (text = "нажми на меня",size_hint = (None,None) ,size = (600,40),pos = (20,50),on_press = self.ButtonOpen)
        self.fl.add_widget(self.but_open)

     def ButtonOpen(self) :
         self.but_open1 = Button (text = "кнопка1",size_hint = (None,None) ,size = (600,40),pos = (20,100))
         self.but_open2 = Button (text = "Не жми на меня",size_hint = (None,None) ,size = (600,40),pos = (20,150))
         self.fl.add_widget(self.but_open1)
         #Аналогично пишем сюда и другие кнопки

class MyApp() :
    def build(self):
        manager = ScreenManager()
    	manager.add_widget(MenuScreen(name = 'menu'))
    	return manager

if __name__ == '__main__' :
    MyApp().run()

* Note:
If it gives an error in the function, try it in the expression
on_press = ( self.ButtonOpen())
I write mainly through kv lang and forgot a little.
I hope this helps you, I'm just a beginner

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question