App for android in python

1

I'm doing my "Hello world" in python, I tell them that I'm taking Kivy to do this but when I run the program I get an error.

import kivy
kivy.require('1.9.0')

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout

class Contenedor_01(BoxLayout):
    None

class MainApp(App):
    title = "Hola mundo"
    def build(self):
        return Contenedor_01()

if __name__ == '__main__':
    MainApp().run(App)

This is the error that appears to me:

  

[INFO] [Logger] Record log in   C: \ Users \ mxe01508121A.kivy \ logs \ kivy_17-07-17_5.txt [INFO] [Kivy
  ] v1.10.0 [INFO] [Python] v3.6.1 (v3.6.1: 69c0db5, Mar 21   2017, 17:54:52) [MSC v.1900 32 bit (Intel)] [INFO] [Factory]   194 symbols loaded [INFO] [Image] Providers: img_tex,   img_dds, img_sdl2, img_gif (img_pil, img_ffpyplayer ignored)   Traceback (most recent call last): File   "C: /Users/mxe01508121A/PycharmProjects/untitled1/main.py", line 16, in           MainApp (). Run (App) TypeError: run () takes 1 positional argument but 2 were given

I hope you can help me a cordial greeting to all.

Edit:

After correcting the previous problem, as indicated in the FJSevilla response, I now get the following error:

[INFO   ] [Logger      ] Record log in C:\Users\mxe01508121A\.kivy\logs\kivy_17-07-17_44.txt        
[INFO   ] [Kivy        ] v1.10.0        
[INFO   ] [Python      ] v3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 17:54:52) [MSC v.1900 32 bit (Intel)]
[INFO   ] [Factory     ] 194 symbols loaded
[INFO   ] [Image       ] Providers: img_tex, img_dds, img_sdl2, img_gif (img_pil, img_ffpyplayer ignored)
[INFO   ] [OSC         ] using <thread> for socket
[INFO   ] [Window      ] Provider: sdl2
[INFO   ] [GL          ] Using the "OpenGL" graphics system
[INFO   ] [GL          ] GLEW initialization succeeded
[INFO   ] [GL          ] Backend used <glew>
[INFO   ] [GL          ] OpenGL version <b'4.4.0 - Build 20.19.15.4483'>        
[INFO   ] [GL          ] OpenGL vendor <b'Intel'>           
[INFO   ] [GL          ] OpenGL renderer <b'Intel(R) HD Graphics 520'>      
[INFO   ] [GL          ] OpenGL parsed version: 4, 4
[INFO   ] [GL          ] Shading version <b'4.40 - Build 20.19.15.4483'>
[INFO   ] [GL          ] Texture max size <16384>
[INFO   ] [GL          ] Texture max units <32>
[INFO   ] [Shader      ] fragment shader: <b"WARNING: 0:7: '' :  #version directive missing">
[INFO   ] [Shader      ] vertex shader: <b"WARNING: 0:7: '' :  #version directive missing">
[WARNING] [Image       ] Unable to load image <C:\Users\mxe01508121A\AppData\Local\Programs\Python\Python36-32\lib\site-packages\kivy\data\glsl\default.png>
[CRITICAL] [Window      ] Unable to find any valuable Window provider.
sdl2 - Exception: SDL2: Unable to load image
  File "C:\Users\mxe01508121A\AppData\Local\Programs\Python\Python36-32\lib\site-packages\kivy\core\__init__.py", line 67, in core_select_lib
    cls = cls()
  File "C:\Users\mxe01508121A\AppData\Local\Programs\Python\Python36-32\lib\site-packages\kivy\core\window\window_sdl2.py", line 140, in __init__
    super(WindowSDL, self).__init__()
  File "C:\Users\mxe01508121A\AppData\Local\Programs\Python\Python36-32\lib\site-packages\kivy\core\window\__init__.py", line 899, in __init__
    self.create_window()
  File "C:\Users\mxe01508121A\AppData\Local\Programs\Python\Python36-32\lib\site-packages\kivy\core\window\window_sdl2.py", line 291, in create_window
    super(WindowSDL, self).create_window()
  File "C:\Users\mxe01508121A\AppData\Local\Programs\Python\Python36-32\lib\site-packages\kivy\core\window\__init__.py", line 1051, in create_window
    self.render_context = RenderContext()
  File "kivy\graphics\instructions.pyx", line 758, in kivy.graphics.instructions.RenderContext.__init__ (kivy\graphics\instructions.c:12580)
  File "C:\Users\mxe01508121A\AppData\Local\Programs\Python\Python36-32\lib\site-packages\kivy\core\image\__init__.py", line 538, in __init__
    self.filename = arg
  File "C:\Users\mxe01508121A\AppData\Local\Programs\Python\Python36-32\lib\site-packages\kivy\core\image\__init__.py", line 734, in _set_filename
    mipmap=self._mipmap, nocache=self._nocache)
  File "C:\Users\mxe01508121A\AppData\Local\Programs\Python\Python36-32\lib\site-packages\kivy\core\image\__init__.py", line 435, in load
    im = loader(filename, **kwargs)
  File "C:\Users\mxe01508121A\AppData\Local\Programs\Python\Python36-32\lib\site-packages\kivy\core\image\__init__.py", line 201, in __init__
    self._data = self.load(filename)
  File "C:\Users\mxe01508121A\AppData\Local\Programs\Python\Python36-32\lib\site-packages\kivy\core\image\img_sdl2.py", line 41, in load
    raise Exception('SDL2: Unable to load image')

[CRITICAL] [App         ] Unable to get a Window, abort.
    
asked by Memo 17.07.2017 в 22:27
source

1 answer

3

run is an instance method of the class kivy.app.App and as such automatically receives as the first argument the instance of the class (argument self by convention).

In your case you call the method run of the object MainApp (which is an instance of the class App ) but you are passing a second argument (in addition to the first that is passed automatically and that is the own instance MainApp ) which is the class itself ( App ):

MainApp().run(App)

Even if you do not see it, the method is being called as:

MainApp().run(MainApp, App)

The method run does not pass any argument to him explicitly, its definition is:

def run(self):

Your code should be:

import kivy
kivy.require('1.9.0')

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout

class Contenedor_01(BoxLayout):
    pass

class MainApp(App):
    title = "Hola mundo"
    def build(self):
        return Contenedor_01()

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

To tell the interpreter to do nothing when a sentence is found that requires another synthetically afterwards (as in the case of the definition of the class Contador _01 ) the sentence pass .

Edit:

The new error that you mention seems to be a problem of installation of libraries, in particular with the dependency sdl2 . I do not know if you followed without errors the installation instructions for Windows as they come in the official documentation:

link

Remember that you have to install the dependencies correctly (without being shown any exceptions in the process) so that Kivy works without problems:

python -m pip install docutils pygments pypiwin32 kivy.deps.sdl2 kivy.deps.glew
    
answered by 17.07.2017 в 22:39