0

I have the following code in a kivy app. I am pasting only the code related to Button as this is what is not working. The rest of the code is about displaying the list data in a datagrid, which works fine.

class PnLScreen(Screen):
    data = ListProperty(defaultvalue=[])
    processing = BooleanProperty(defaultvalue=False)

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        tryout.get_nse_prices()
        tryout.get_bse_prices()
        tryout.get_isin_to_symbol_map()
        self.box = BoxLayout(orientation='vertical')
        button = Button(size_hint_y=None)
        button.bind(on_press=self.go_home)
        self.box.add_widget(button)

    def go_home(self,instance):
        print("called from %s" % instance.text)
        # will figure out how to go home!

Now the button is displayed when the screen becomes current. But on clicking on the button, the bound function go_home is never called. I use buttons in other screens where it works. So I am not sure why this will not! Actually I am quite exasperated not being able to get this simple thing working.

Thanks in advance

1 Answer 1

0

You added the button to the boxlayout at self.box.add_widget(button), but you didn't add the boxLayout to PnLScreen. (self.add_widget(self.box)). Which means both the button and the boxlayout will never be displayed. So the button you clicked was different from the one you created in the code above.

4
  • Thanks. I did that , that is , self.add_widget(self.box). The button is displayed, but the press event is simply not generated( or propagated). Not sure how to debug this. This works for buttons on the main screen( i have two screens).
    – srajan
    Oct 28, 2020 at 12:23
  • Then I have no idea. If you post a runnable example that re-produce the issue, I might be able to find the cause of the issue. Oct 28, 2020 at 12:29
  • Sorry I don't wanna debug your entire application. I'd suggest using the inspector to figure out which button you pressed. kivy.org/doc/stable/api-kivy.modules.html Oct 28, 2020 at 12:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.