Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weird interaction with Tkinter #10239

Closed
rdwmpls opened this issue Jan 12, 2018 · 4 comments
Closed

Weird interaction with Tkinter #10239

rdwmpls opened this issue Jan 12, 2018 · 4 comments

Comments

@rdwmpls
Copy link

rdwmpls commented Jan 12, 2018

Bug report

Bug summary

Importing matplotlib before creating a Tk instance causes a crash.

Code for reproduction
Bad:

import Tkinter as tk
import matplotlib.pyplot as plt
root = tk.Tk()

Ok:

import Tkinter as tk
root = tk.Tk()
import matplotlib.pyplot as plt

Actual outcome

ron ~ $ python
Python 2.7.14 |Anaconda custom (64-bit)| (default, Oct  5 2017, 02:28:52) 
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import Tkinter as tk
>>> import matplotlib.pyplot as plt
>>> root = tk.Tk()
2018-01-12 16:11:38.882 python[3561:147192] -[NSApplication _setup:]: unrecognized selector sent to instance 0x7fe13ec690e0
2018-01-12 16:11:38.883 python[3561:147192] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSApplication _setup:]: unrecognized selector sent to instance 0x7fe13ec690e0'
*** First throw call stack:
(
	0   CoreFoundation                      0x00007fff4533e1fb __exceptionPreprocess + 171
	1   libobjc.A.dylib                     0x00007fff6bfbf942 objc_exception_throw + 48
	2   CoreFoundation                      0x00007fff453d5714 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
	3   CoreFoundation                      0x00007fff452b5b53 ___forwarding___ + 1443
	4   CoreFoundation                      0x00007fff452b5528 _CF_forwarding_prep_0 + 120
	5   libtk8.6.dylib                      0x000000010400146f TkpInit + 383
	6   libtk8.6.dylib                      0x0000000103f5a21e Initialize + 2622
	7   _tkinter.so                         0x0000000103d81be4 Tcl_AppInit + 84
	8   _tkinter.so                         0x0000000103d81448 Tkinter_Create + 1128
	9   libpython2.7.dylib                  0x000000010394f8f4 PyEval_EvalFrameEx + 22980
	10  libpython2.7.dylib                  0x0000000103949cd4 PyEval_EvalCodeEx + 2164
	11  libpython2.7.dylib                  0x00000001038cbbb3 function_call + 355
	12  libpython2.7.dylib                  0x00000001038a34d5 PyObject_Call + 101
	13  libpython2.7.dylib                  0x00000001038b2642 instancemethod_call + 162
	14  libpython2.7.dylib                  0x00000001038a34d5 PyObject_Call + 101
	15  libpython2.7.dylib                  0x0000000103953a2f PyEval_CallObjectWithKeywords + 159
	16  libpython2.7.dylib                  0x00000001038b05d4 PyInstance_New + 148
	17  libpython2.7.dylib                  0x00000001038a34d5 PyObject_Call + 101
	18  libpython2.7.dylib                  0x000000010394f578 PyEval_EvalFrameEx + 22088
	19  libpython2.7.dylib                  0x0000000103949cd4 PyEval_EvalCodeEx + 2164
	20  libpython2.7.dylib                  0x0000000103949452 PyEval_EvalCode + 34
	21  libpython2.7.dylib                  0x0000000103976ba1 PyRun_InteractiveOneFlags + 385
	22  libpython2.7.dylib                  0x000000010397659e PyRun_InteractiveLoopFlags + 110
	23  libpython2.7.dylib                  0x0000000103976450 PyRun_AnyFileExFlags + 64
	24  libpython2.7.dylib                  0x000000010398d572 Py_Main + 3506
	25  libdyld.dylib                       0x00007fff6cbac115 start + 1
	26  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

Expected outcome

Too obvious to need to describe.

Matplotlib version

  • Operating system: macOS High Sierra (version 10.13.2)
  • Matplotlib version: 2.1.0
  • Matplotlib backend: MacOSX
  • Python version: Python 2.7.14 |Anaconda custom (64-bit)| (default, Oct 5 2017, 02:28:52)
  • Jupyter version (if applicable): N/A
  • Other libraries: N/A
@tacaswell
Copy link
Member

I am not surprised if there are issues as you are trying to run two different GUI frameworks. If you do matplotlib.use('tkagg') before importing pyplot does this issue go away?

Gem-Atkinson added a commit to GCA-VH-lab/FlaGs that referenced this issue Jul 2, 2018
the -to was failing with Gemma's installation due to a Tkinter issue (see matplotlib/matplotlib#10239)

Making the tkinter instance  master = Tk() immediately after importing tkinter fixed the problem
@rudrathegreat
Copy link

The link below gives really good code on how to combine matplotlib and tkinter -

https://pythonprogramming.net/how-to-embed-matplotlib-graph-tkinter-gui/

And what @tacaswell is saying is right. That line is the backend for matplotlib which gives it the functionality to work together with tkinter

@QuLogic
Copy link
Member

QuLogic commented Nov 8, 2018

I'm going to close this as it's been 10 months without a response from the reporter. Please comment if there is still an issue.

@jwbrown
Copy link

jwbrown commented Jan 1, 2022

Using matplotlib.use('tkagg')
worked for me... took a while to find this post though, but thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants