pygame-community / pygame-ce

🐍🎮 pygame - Community Edition is a FOSS Python library for multimedia applications (like games). Built on top of the excellent SDL library.
https://pyga.me
814 stars 127 forks source link

Cannot Use Tkinter With Pygame on MacOS (2639) #1364

Open GalacticEmperor1 opened 1 year ago

GalacticEmperor1 commented 1 year ago

Issue №2639 opened by DivyanshByte at 2021-07-16 10:57:13

Environment:

Current behavior:

When I Make A tkinter Window after initializing Pygame, this error is Coming:

pygame 2.0.1 (SDL 2.0.14, Python 3.9.6)
Hello from the pygame community. https://www.pygame.org/contribute.html
2021-07-16 16:21:32.761 Python[5395:130550] -[SDLApplication _setup:]: unrecognized selector sent to instance 0x7fdfd0d0fed0
2021-07-16 16:21:32.763 Python[5395:130550] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SDLApplication _setup:]: unrecognized selector sent to instance 0x7fdfd0d0fed0'
*** First throw call stack:
(
        0   CoreFoundation                      0x00007fff4d7e4a7d __exceptionPreprocess + 256
        1   libobjc.A.dylib                     0x00007fff77eb8a17 objc_exception_throw + 48
        2   CoreFoundation                      0x00007fff4d85e886 -[NSObject(NSObject) __retain_OA] + 0
        3   CoreFoundation                      0x00007fff4d7868ef ___forwarding___ + 1485
        4   CoreFoundation                      0x00007fff4d786298 _CF_forwarding_prep_0 + 120
        5   libtk8.6.dylib                      0x00000001066c91f2 TkpInit + 408
        6   libtk8.6.dylib                      0x0000000106638aac Initialize + 2454
        7   _tkinter.cpython-39-darwin.so       0x000000010648c6d4 Tcl_AppInit + 84
        8   _tkinter.cpython-39-darwin.so       0x000000010648bff2 _tkinter_create + 1362
        9   Python                              0x0000000103c9186a cfunction_vectorcall_FASTCALL + 218
        10  Python                              0x0000000103d2b58c call_function + 732
        11  Python                              0x0000000103d28ab3 _PyEval_EvalFrameDefault + 25219
        12  Python                              0x0000000103d2c283 _PyEval_EvalCode + 2611
        13  Python                              0x0000000103c538d1 _PyFunction_Vectorcall + 289
        14  Python                              0x0000000103c52fd5 _PyObject_FastCallDictTstate + 293
        15  Python                              0x0000000103c53bb8 _PyObject_Call_Prepend + 152
        16  Python                              0x0000000103cad325 slot_tp_init + 165
        17  Python                              0x0000000103ca8879 type_call + 345
        18  Python                              0x0000000103c5317d _PyObject_MakeTpCall + 365
        19  Python                              0x0000000103d2b61c call_function + 876
        20  Python                              0x0000000103d28b4b _PyEval_EvalFrameDefault + 25371
        21  Python                              0x0000000103d2c283 _PyEval_EvalCode + 2611
        22  Python                              0x0000000103d2270b PyEval_EvalCode + 139
        23  Python                              0x0000000103d762a3 pyrun_file + 387
        24  Python                              0x0000000103d74602 PyRun_SimpleFileExFlags + 850
        25  Python                              0x0000000103d916a9 Py_RunMain + 1801
        26  Python                              0x0000000103d91b3f pymain_main + 223
        27  Python                              0x0000000103d91d3b Py_BytesMain + 43
        28  libdyld.dylib                       0x00007fff796863d5 start + 1
        29  ???                                 0x0000000000000002 0x0 + 2
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Abort trap: 6

Expected behavior:

It Should Open Tkinter Window.

Steps to reproduce:

  1. Run the Code Below
  2. Python Will Crash and Give the Above Error

Code

import pygame as pg
pg.init()
from tkinter import *
window = Tk()
window.mainloop()

Comments

*robertpfeiffer commented at 2021-07-19 08:05:02*

This is a well-known limitation in TkInter, and the reason you should not use IDLE with PyGame. We probably can't fix this in the forseeable future. Maybe we need a prominent "gotchas" page in the docs where this is mentioned.


*DivyanshByte commented at 2021-07-20 11:18:58*

And This Would Work on Windows, But not On Mac.

MyreMylar commented 3 months ago

The code in this issue works fine on Windows. Would be good to retest on modern macs.