0

I get this error message when trying to run my code in PyCharm. I'm not sure if I installed something incorrectly, can someone please help?

sdl2 - ImportError: DLL load failed: The specified module could not be found.
File "C:\Users\Donovan Preston\AppData\Local\Programs\Python\Python36-32\lib\site-packages\kivy\core\__init__.py", line 59, in core_select_lib
    fromlist=[modulename], level=0)
File "C:\Users\Donovan Preston\AppData\Local\Programs\Python\Python36-32\lib\site-packages\kivy\core\window\window_sdl2.py", line 26, in <module>
    from kivy.core.window._window_sdl2 import _WindowSDL2Storage

 [CRITICAL] [App         ] Unable to get a Window, abort.

This is the code I'm trying to run in PyCharm.

import kivy
from kivy.app import App
from kivy.uix.dropdown import DropDown
from kivy.uix.floatlayout import FloatLayout
from kivy.config import Config


class SubMenu(DropDown):
    pass


class MainMenu(FloatLayout):

    def display_selected_submenu(self, instance, x):
        print("Page " + x)


class TestApp(App):
    title = "Kivy Drop-Down List Demo"
    Config.set("graphics", "width", "800")
    Config.set("graphics", "height", "480")

    def build(self):
        return MainMenu()

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

1 Answers1

0

I have no problem running the example on PyCharm Community Edition 2017.2, Windows 10, Python 3.6.2, and Kivy 1.10.0

Did you install the dependencies? If not, do the following:

python -m pip install docutils pygments pypiwin32 kivy.deps.sdl2 kivy.deps.glew

Example

main.py

from kivy.app import App
from kivy.uix.dropdown import DropDown
from kivy.uix.floatlayout import FloatLayout
from kivy.config import Config


class SubMenu(DropDown):
    pass


class MainMenu(FloatLayout):

    def display_selected_submenu(self, instance, x):
        print("Page " + x)


class TestApp(App):
    title = "Kivy Drop-Down List Demo"
    Config.set("graphics", "width", "800")
    Config.set("graphics", "height", "480")

    def build(self):
        return MainMenu()


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

test.kv

#:kivy 1.10.0
#:import Factory kivy.factory.Factory

<CustomButton@Button>:
    size_hint_y: None
    height: 40
    font_size: 18


<SubMenu>:
    on_select: app.root.display_selected_submenu(self, args[1])

    CustomButton:
        id: button1
        text: 'Open'
        txt: "1"
        on_release: root.select(self.txt)

    CustomButton:
        id: button2
        text: 'Save'
        txt: "2"
        on_release: root.select(self.txt)

    CustomButton:
        id: button3
        text: 'Exit'
        txt: "3"
        on_release: root.select(self.txt)

<MainMenu>:
    canvas.before:
        Color:
            rgba: 0.5, 0.5, 0.5, 0.5
        Rectangle:
            pos: 0,0
            size: self.width, self.height

    Button:
        id: mainbutton
        text: "File Menu"
        font_size: 20
        size_hint: None, None
        size: 150, 50
        top: root.top
        on_release: Factory.SubMenu().open(self)

Output

enter image description here

ikolim
  • 15,721
  • 2
  • 19
  • 29
  • I have the dependencies installed, I'm not sure what else is wrong because it still isnt working – Donovan Preston Sep 28 '17 at 16:14
  • If you are still experiencing the problem, please refer to my post at https://stackoverflow.com/questions/49466785/kivy-error-python-2-7-sdl2-import-error/49477111#49477111. Thank you. – ikolim Mar 25 '18 at 14:49