Kivy(framework): blank window after running code

Viewed 35

After running this code python idle gave me a blank window without any kivy widgets and python idle does not show any error. what is the problem in this code? screen shot of blank window


code:

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


class me(App):
     def __init__(self,b,g,l,t):
          super(me, self).__init__()
          self.b=Button(text='start')
          self.g=GridLayout(cols=4)
          self.l=Label(text='label')
          self.t=TextInput()
          self.g.add_widget(self.b)
          self.g.add_widget(self.t)
          self.g.add_widget(self.l)


m=me('b','g','l','t')

m.run()

1 Answers

Building the App should be done in a build() method of the App, and that method should return the root widget for the App. Like this:

class me(App):
     def __init__(self,b,g,l,t):
          super(me, self).__init__()
          self.b=Button(text='start')
          self.g=GridLayout(cols=4)
          self.l=Label(text='label')
          self.t=TextInput()
          self.g.add_widget(self.b)
          self.g.add_widget(self.t)
          self.g.add_widget(self.l)

    def build(self):
        return self.g
Related