2

Reference: MacOS 10.14, Python 3.6 from Anaconda, Spyder 3.3.4

I'm just getting started with tkinter in Python, and am trying to run a simple demo code found here from within Spyder. For completeness, the 6-line script is as follows:

import tkinter as tk 
r = tk.Tk() 
r.title('Counting Seconds') 
button = tk.Button(r, text='Stop', width=25, command=r.destroy) 
button.pack() 
r.mainloop()

When I run this, however, it hangs. No beach ball, no freezing, just nothing happening. The only way to get out of the hung command is to re-start the IPython kernel, or close and re-launch Spyder.

I think I've traced the problem line to:

r = tk.Tk()

which causes a hang in the same way if executed by itself.

I know there are a number of issues between Tkinter and Python on MacOS (e.g. this), but none that I've seen seem to recreate this specific issue.

Any ideas?

Matt
  • 43
  • 6
  • i think Spyder doesn't work properly with tkinter. Try `python3 -m tkinter` on terminal and if a window pops up without any hang then tkinter is good to on your mac and you should try some other IDE like vscode or IDLE but in case if it hangs then try installing anaconda again. I've been working with tkinter on mac 10.15.0, anaconda, vscode 1.35.0 and i faced no such issues so far. – Saad Jun 19 '19 at 05:47
  • Thanks @Saad for your comment. Indeed, I get a window when I run python3 -m tkinter from the command line, and the script above works without error when run in IDLE. However, it only works in IDLE running Python 2.6; when I try to launch the IDLE associated with my Python 3.6, the editor shows up blank. This also seems to be related to the tcl/tk issues on mac (e.g. [here](https://stackoverflow.com/questions/48750115/blank-python-idle-window-when-opening-python-file-on-macos)), so I think the Python page I linked to above may be the solution. Thanks for the helpful comment. – Matt Jun 19 '19 at 16:26
  • If you have the dark mode on then it does. Probably this [answer](https://stackoverflow.com/a/55516222/10364425) might help you. I had some what a similar issue. In short on mac the default version of Tcl/Tk is 8.5 i guess, which has some issues and apple just doesn't update. So new python bundles comes with their own Tcl/Tk versions. – Saad Jun 19 '19 at 16:33
  • @Saad I do have dark mode enabled, but the blank IDLE3.6 window is not black as your answer suggests is should be. And, in addition, I am running tk/tcl 8.6.9 so the old tcl/tk version is not the issue here. Any other thoughts? – Matt Jun 19 '19 at 16:50
  • Python on IDLE and python on anaconda both are different thing, both have their own Tcl/Tk versions. Try disable dark mode and run it and also you can try install and use vscode straight from anaconda-navigator. – Saad Jun 19 '19 at 16:56

1 Answers1

1

Thanks in part to some helpful comments from @Saad , I think I figured out the issue. Python 3.6.7 (from Anaconda) and tk/tcl 8.6.9 don't seem to play nice. If I downgrade tk/tcl to 8.6.8, everything works fine, no matter the IDE I use.

Matt
  • 43
  • 6