Denis Omelchenko
Denis Omelchenko

Reputation: 69

How to fix Tkinter? Every code with GUI crashes mac os with respring

I was practicing tkinter with PyCharm for my own project with serial and arduino. Nothing special about it - few buttons, option-menu and labels. But I clicked on Mac's menu bar in the tkinter's GUI window on the option "Show tab bar". And then macbook had a reboot. After it - every script with tkinter's GUI reboots my macbook on executing. A blank window is shown for a second and then mac reboots. I'm using Mojave 10.14.6 (18G84)

I deleted python 3.7 interpreter from mac and reinstalled PyCharm. I cleared cache folders for python and PyCharm.

import tkinter
tkinter._test() # and it crashes now ever in this code...

UPD: updated MacOS to 10.14.6 (18G87) - still the same issue

Upvotes: 6

Views: 11463

Answers (9)

ericgao4
ericgao4

Reputation: 1

I meet the same problem, and I recently founded a solution.

First, open terminal and type "python" to enter in the python 2.7 provided by macOS.

Then type:

 import Tkinter as tk
 print("Tk Version: {}".format(tk.Tk().eval('info patchlevel')))

Then it will pop up a normal tk window in python2.7 version and tk version 8.5.9. Then redo the same thing that crashes the python3's tk, that is "clicked on Mac's menu bar in the tkinter's GUI window on the option 'Show tab bar'". But this time, it will change to 'Hide tab bar'. After you click it, the tk's tab bar will disappear.

After that, your tk in python3 and tk version 8.6.x should operate normally.

I think this is a bug in macOS. When showing tab bar in tk version 8.6.x(not the tk 8.5.9 provided by macOS), the macOS will crashed. And the solution above is just canceled the showing of tab bar, so it's not 'really' solved the bug. So looks like you need to update to macOS 10.15 to really solve it. And that means you still not able to 'show tab bar' in macOS 10.14 with tk version 8.6.x.

Upvotes: 0

Adam Lyu
Adam Lyu

Reputation: 11

I have the same issue with python 3.7.0, tk 8.6.8 in anaconda3 in macOS 10.14.6: once I start my tk interface script the OS logs out without an error message showed or error report filed. Windows are also lost.

My problem was solved once I update to macOS 10.15.3. Tk is working properly and haven't spotted a new issue.

Upvotes: 1

Max
Max

Reputation: 11

I ran into this issue on Mojave 10.14.6 after installing python 3.7.4 and tkinter 8.6.8 using Miniconda3.

Downgrading to python 3.7.0 fixed this issue for me.

conda install python=3.7.0

Upvotes: 1

Breen
Breen

Reputation: 11

I struggled with this same problem; code starts running (mac os 10.14.6 Mojave) and then I'm looking at my log in screen. After I log back in, PyCharm is also shutdown as is my chrome browser.

Here's what worked for me:

1) python 3.8.1 - I also got it running on python 3.6, so probably 3.7 would work, too.

2) Install ActiveTCL 8.6 - from ActiveState. Background ref is here.

3) I could not get any virtual environments to work with tkinter in PyCharm - I tried several iterations each of miniconda and virtualenv. The Python interpreter had to be the regular installed path - ie my path is /usr/local/binpython3.8 This could just be a quirk of my system...but I figured it could be useful for others.

Upvotes: 0

a_random_programmer
a_random_programmer

Reputation: 148

Any system interpreter seems to work fine for me. As @Rfm0905 said, use brew to install the system interpreter if you do not have it. However, you can do this for any python version using brew install python${version}. This version, as far as I know, could be 3 (for python 3.7.5) or 2 (for python 2.7.4).

Upvotes: 0

BPDESILVA
BPDESILVA

Reputation: 2198

Seems to be a common problem python.org/download/mac/tcltk/#built-in-8-6-8 according to them

If you are using macOS 10.6 or later, the Apple-supplied Tcl/Tk 8.5 has serious bugs that can cause application crashes.

Rather than fixing TCL/TK I recommend you to want to reinstall a python version that satisfies the requirement & use it python.org/downloads/release/python-374

Upvotes: 1

Nik Pavlenko
Nik Pavlenko

Reputation: 11

Have you tried to downgrade tkinter to a version below the one causing a crash?

I.e going from 8.6.8 to 8.6.7 in conda can be done by executing:

conda install tk 8.6.7 

this is all it took to fix an identical issue and error log, might also work with pip

Upvotes: 1

Rfm0905
Rfm0905

Reputation: 1

I was using a Conda virtual environment for python 2, switching to a System Interpreter solved the issue for me. If you don't have a System Interpreter, use

$ brew install python@2

and use this interpreter to run the program. In PyCharm you would open your project, go to preferences -> project -> interpreter and select the 2.7 interpreter you installed.

Upvotes: 0

Ivan Vazquez
Ivan Vazquez

Reputation: 31

A somewhat long explanation of the problem can be found here. It looks like you should avoid using a third party distributer of python.

I had the same problem. Your code made my computer crash. To fix it I had to install python from here. This will become your system's python 3.7 version. I uninstalled anaconda and used the system's 3.7 interpreter in PyCharm. Next, I had to start installing packages to make my code work. This may seem a bit tedius/difficult. Unfortunately, everything else I tried failed.

enter image description here

Upvotes: 0

Related Questions