2

I am new to the kivy GUI package and wanted to learn to make a game by following the 'Pong Game Tutorial' on the official site. I entered the basic code to open up a GUI window which worked just fine. However when I close this window and rerun the same code again I get an ArgumentError. I am using the latest version of Spyder as IDE and have updated all packages.

The only thing that circumvents this problem is restarting Spyder. Am I doing something wrong in the execution?

The code should open up a new window every time it is executed. After the first run I get this console output however which ends in an ArgumentError.

The Code:

from kivy.app import App
from kivy.uix.widget import Widget


class PongGame(Widget):
    pass


class PongApp(App):
    def build(self):
        return PongGame()


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

The console output

[INFO   ] [Base        ] Start application main loop
[ERROR  ] [Base        ] No event listeners have been created
[ERROR  ] [Base        ] Application will leave
[INFO   ] [Base        ] Leaving application in progress...
[INFO   ] [Base        ] Leaving application in progress...
Traceback (most recent call last):

  File "<ipython-input-2-30ebdb31c7db>", line 17, in <module>
    PongApp().run()

  File "C:\Users\almig\Anaconda3\lib\site-packages\kivy\app.py", line 855, in run
    runTouchApp()

  File "C:\Users\almig\Anaconda3\lib\site-packages\kivy\base.py", line 506, in runTouchApp
    stopTouchApp()

  File "C:\Users\almig\Anaconda3\lib\site-packages\kivy\base.py", line 521, in stopTouchApp
    EventLoop.close()

  File "C:\Users\almig\Anaconda3\lib\site-packages\kivy\base.py", line 172, in close
    self.stop()

  File "C:\Users\almig\Anaconda3\lib\site-packages\kivy\base.py", line 184, in stop
    provider.stop()

  File "C:\Users\almig\Anaconda3\lib\site-packages\kivy\input\providers\wm_pen.py", line 111, in stop
    SetWindowLong_WndProc_wrapper(self.hwnd, self.old_windProc)

  File "C:\Users\almig\Anaconda3\lib\site-packages\kivy\input\providers\wm_common.py", line 122, in _closure
    oldAddr = func(hWnd, GWL_WNDPROC, cast(wndProc, c_void_p).value)

ArgumentError: argument 3: <class 'TypeError'>: wrong type
dschingchris
  • 139
  • 1
  • 10
  • The code that throws the error is written by me (when fixing https://stackoverflow.com/questions/55928463/ctypes-argumenterror-when-using-kivy-with-pywinauto/55931295#55931295). I tried reproducing it on *Python 3.7* *VEnv*s (*64bit* / *32bit*) with *Kivy* versions containing the fix, but it works. Might be an initialization problem? – CristiFati Jun 26 '19 at 10:09
  • Sorry to ask such a rookie question, but at which point do you assume an initialization problem? The kivy package importation? The spyder IDE? I've gone through a lot of kivy tutorials on pages and on youtube but virtually all just use these basic code snips. – dschingchris Jun 26 '19 at 11:46
  • I assume that at some point, `self.old_windProc` becomes *None* (0). That would generate this error. That member is initialized in the *start* method. I can guess that it's only called the 1st time. Unfortunately, I don't know what *Spyder* does when closing the window. I can see a trivial fix on *Kivy*'s side, but I'm not sure that's a supported scenario. – CristiFati Jun 26 '19 at 11:55
  • This sounds like a bug in Kivy that's being triggered by a semi-unusual behaviour of spyder - it looks like Kivy doesn't clean up after itself properly so you can't run a second app after the first returns. This doesn't normally matter much, but is a problem here because spyder is reusing the same interpreter instance. Does it maybe have an option to run a new python process each time? – inclement Jun 26 '19 at 19:40

2 Answers2

0

You can make spyder run a new process each for each execution. Go to Run menu and choose "Configuration per file..." (Ctrl+F6) and select "Execute in an external system terminal" under "Console".

Ananth
  • 11
  • 1
-1

Simply go Menu --> Run --> Configuration per file --> Execute in an external system terminal --> OK.

That should work

938MeV
  • 1