0

I am trying to create a simple app with kivy in python but when i run this code i get following error RecursionError: maximum recursion depth exceeded in comparison

import wikipedia
from kivy.app import App
from kivy.uix.popup import Popup
from kivy.uix.label import Label
from kivy.uix.gridlayout import GridLayout
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button


class GridLayout(GridLayout):

    def __init__(self, **kwargs):
        super(GridLayout, self).__init__()
         # Number of columns
        self.cols = 1
         

         # Second grid Layout
        self.second_layout = GridLayout()
        self.second_layout.cols = 2

        # Creating a text field to show the result of entered query
        self.query_result = TextInput(text='', size_hint_y=0.8)
        self.second_layout.add_widget(self.query_result)  # Adding query result on the screen

        # Creating a text input field to get the query from user
        self.query = TextInput(text='', multiline=False, hint_text="Enter your Query", size_hint_y=0.1, font_size=20)
        self.second_layout.add_widget(self.query)


        # Adding Second layout on the screen
        self.add_widget(second_layout)


        # Creating a submit button
        self.submit_button = Button(text="Submit", size_hint_y=0.1, font_size=40, on_press=self.submit)
        self.add_widget(self.submit_button)

        def submit(self, instance):
            try:
               query_result_from_wikipedia = wikipedia.page(self.query.text).summary
               self.query_result.text = query_result_from_wikipedia
            except:
               popup = Popup(title='Query Not Found',
                      content=Label(text='Try to Search Anything else'),
                      size_hint=(None, None), size=(400, 400))
               popup.open()


class MyApp(App):
    def build(self):
        return GridLayout()


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

But when i remove the second gridlayout from it it runs without errors

1 Answer 1

1

The first problem is the name of your class. Don't name a class the same as its subclass:

class GridLayout(GridLayout):

is likely to cause problems. Just change it to something like:

class MyGridLayout(GridLayout):
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.