Reputation: 73
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?
Upvotes: 1
Views: 1515
Reputation: 33714
Here I will point out your mistakes and how to solve your problem.
true
is called True
in pythonK_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;
at every line breakspygame = pygame
and turtle = turtle
since the import comes with the namesAnd 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.
Upvotes: 2