1

I get this error code:

2017-04-13 03:04:14.958 Python[606:839244] -[SDLApplication _setup:]: unrecognized selector sent to instance 0x1007a0dd0
2017-04-13 03:04:14.971 Python[606:839244] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SDLApplication _setup:]: unrecognized selector sent to instance 0x1007a0dd0'
*** First throw call stack:
(
    0   CoreFoundation                      0x00007fff8d71be7b __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x00007fffa22fbcad objc_exception_throw + 48
    2   CoreFoundation                      0x00007fff8d79dcb4 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
    3   CoreFoundation                      0x00007fff8d68dfb5 ___forwarding___ + 1061
    4   CoreFoundation                      0x00007fff8d68db08 _CF_forwarding_prep_0 + 120
    5   Tk                                  0x000000010324b5e6 TkpInit + 471
    6   Tk                                  0x00000001031c6c8d Tk_Init + 1794
    7   _tkinter.cpython-36m-darwin.so      0x00000001027e7dfd Tcl_AppInit + 77
    8   _tkinter.cpython-36m-darwin.so      0x00000001027e5849 _tkinter_create + 889
    9   Python                              0x000000010006a688 _PyCFunction_FastCallDict + 568
    10  Python                              0x00000001000f33e4 call_function + 612
    11  Python                              0x00000001000f8d84 _PyEval_EvalFrameDefault + 21892
    12  Python                              0x00000001000f27a0 _PyEval_EvalCodeWithName + 2720
    13  Python                              0x00000001000f2fab fast_function + 219
    14  Python                              0x00000001000f33cb call_function + 587
    15  Python                              0x00000001000f8d84 _PyEval_EvalFrameDefault + 21892
    16  Python                              0x00000001000f37cc _PyFunction_FastCallDict + 828
    17  Python                              0x000000010000e984 _PyObject_FastCallDict + 356
    18  Python                              0x000000010000eaa0 _PyObject_Call_Prepend + 208
    19  Python                              0x000000010000e5b3 PyObject_Call + 99
    20  Python                              0x0000000100089871 slot_tp_init + 81
    21  Python                              0x0000000100080144 type_call + 212
    22  Python                              0x000000010000e8d4 _PyObject_FastCallDict + 180
    23  Python                              0x00000001000f3225 call_function + 165
    24  Python                              0x00000001000f8d84 _PyEval_EvalFrameDefault + 21892
    25  Python                              0x00000001000f37cc _PyFunction_FastCallDict + 828
    26  Python                              0x000000010000e984 _PyObject_FastCallDict + 356
    27  Python                              0x000000010000eaa0 _PyObject_Call_Prepend + 208
    28  Python                              0x000000010000e5b3 PyObject_Call + 99
    29  Python                              0x0000000100089871 slot_tp_init + 81
    30  Python                              0x0000000100080144 type_call + 212
    31  Python                              0x000000010000e8d4 _PyObject_FastCallDict + 180
    32  Python                              0x00000001000f3225 call_function + 165
    33  Python                              0x00000001000f8d84 _PyEval_EvalFrameDefault + 21892
    34  Python                              0x00000001000f312e fast_function + 606
    35  Python                              0x00000001000f33cb call_function + 587
    36  Python                              0x00000001000f8d84 _PyEval_EvalFrameDefault + 21892
    37  Python                              0x00000001000f27a0 _PyEval_EvalCodeWithName + 2720
    38  Python                              0x00000001000f3636 _PyFunction_FastCallDict + 422
    39  Python                              0x000000010000e984 _PyObject_FastCallDict + 356
    40  Python                              0x000000010000eaa0 _PyObject_Call_Prepend + 208
    41  Python                              0x000000010000e5b3 PyObject_Call + 99
    42  Python                              0x0000000100089871 slot_tp_init + 81
    43  Python                              0x0000000100080144 type_call + 212
    44  Python                              0x000000010000e8d4 _PyObject_FastCallDict + 180
    45  Python                              0x00000001000f3225 call_function + 165
    46  Python                              0x00000001000f8d84 _PyEval_EvalFrameDefault + 21892
    47  Python                              0x00000001000f312e fast_function + 606
    48  Python                              0x00000001000f33cb call_function + 587
    49  Python                              0x00000001000f8d84 _PyEval_EvalFrameDefault + 21892
    50  Python                              0x00000001000f27a0 _PyEval_EvalCodeWithName + 2720
    51  Python                              0x00000001000f2944 PyEval_EvalCode + 100
    52  Python                              0x000000010012f21e PyRun_FileExFlags + 206
    53  Python                              0x000000010012f4bf PyRun_SimpleFileExFlags + 447
    54  Python                              0x0000000100148ada Py_Main + 3914
    55  Python                              0x0000000100000dfe Python + 3582
    56  Python                              0x0000000100000c34 Python + 3124
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Abort trap: 6

My code is

#!/Library/Frameworks/Python.framework/Versions/3.6/bin/


import sys;
import log;


# Initialization
print(log.GetTime());

import pygame;
import turtle;


pygame = pygame;
turtle = turtle;

# After Initialization
pygame.init();
turtle.begin_fill();

player = {
    'speed': {
        'move': 5,
        'rotate': 1
    }
};

while true:
    time = log.GetTime();
    keys = pygame.key.get_pressed();

    if keys[K_ESCAPE]: break;
    if keys[K_W]: turtle.forward(player.speed.move);
    if keys[K_S]: turtle.backward(player.speed.move);
    if keys[K_A]: turtle.left(player.speed.rotate);
    if keys[K_D]: turtle.right(player.speed.rotate);

print('Ended program!');

I am very very new to python programming, and have no experience in what this is. I have tried looking for answers to fix this, but quite hard when I don't know what's wrong, could anyone tell me how I could fix the issue? What did I do wrong?

5
  • How are you running the code? Why is it in #!/Library/Frameworks/Python.framework/Versions/3.6/bin/? Probably put it in a regular folder, like ~/Dev/MyProject/myprogram.py and run it with python myprogram.py from that folder.
    – bananafish
    Apr 13, 2017 at 1:12
  • Also, while true: is not legal code. You need to post functioning code, not pseudo-code. Apr 13, 2017 at 1:25
  • This code contains many problems, please fix them...and btw, what is log? where did you get it? the log from pypi does not have a GetTime() method. As a side note, you do not need semicolons at new of lines, it just make it look less python.
    – Taku
    Apr 13, 2017 at 1:28
  • @bananafish Because that is where all of the modules are stored
    – Alliator
    Apr 13, 2017 at 1:33
  • @abccd log is a module I have created myself. The function simply outputs: 'HH:MM:SS'
    – Alliator
    Apr 13, 2017 at 1:33

1 Answer 1

2

Here I will point out your mistakes and how to solve your problem.

  1. true is called True in python
  2. K_ESCAPE, K_W... isn't defined, I don't know where you got your names from but you gotta figure that out yourself. You probably meant pygame.K_ESCAPE, pygame.K_w...note: they are lower cased
  3. python does not require ; at every line breaks
  4. you do not need pygame = pygame and turtle = turtle since the import comes with the names
  5. getting item from dict uses [] not .
  6. calling turtle's left/right turns the cursor by that angle not move left/right

And here's how you can stop it from crashing:

import sys
import log


# Initialization
print(log.GetTime())

import pygame
import turtle


# After Initialization
turtle.begin_fill()
pygame.init()


player = {
    'speed': {
        'move': 5,
        'rotate': 1
    }
};

while True:
    time = log.GetTime()
    keys = pygame.key.get_pressed()

    if keys[pygame.K_ESCAPE]: break
    if keys[pygame.K_W]: turtle.forward(player['speed']['move'])
    if keys[pygame.K_S]: turtle.backward(player['speed']['move'])
    if keys[pygame.K_A]: turtle.left(player['speed']['rotate'])
    if keys[pygame.K_D]: turtle.right(player['speed']['rotate'])

print('Ended program!')

You will need to swap places with turtle.begin_fill() and pygame.init() since both pygame and turtle uses the base module tkinter, but only one Tk() (the window) is allowed at a time, but turtle does not know how to use the existing window that pygame created, so the app crashed. While pygame knows how to use the existing window turtle created.

As a side note, it's not necessary to use pygame with turtle, just use tkinter and it has way more functionalities. Plus, you don't even need either of them, turtle have enough functions to do what you wanted.

EDIT: pygame and turtle will never work well together. recommend using tkinter.

1
  • Thanks for pointing this out, I decided to make my program in node.js cause' I am more familiar with JavaScript!
    – Alliator
    Apr 13, 2017 at 5:32

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.