Reputation: 101
Tkinter background appears black upon running script no matter how I attribute the background colour.
I'm using PyCharm CE 2021.3.2 on macOS 12.2.1.
Python Interpreter = Python 3.8 with 5 packages (as follows):
Window looks like this: Black, blank Tkinter window
I've tried:
import tkinter as tk
window = tk.Tk()
window.title("Test")
window.geometry("600x400")
window.mainloop()
Tried changing with window.configure(bg="white")
as well as window['bg'] = "white"
and window['background'] = "white"
to no avail.
Upvotes: 6
Views: 10316
Reputation: 61
Idk if anyone else is still stuck with this, this post solved my problem.
Basically it's the pyenv
grabbing the wrong version of tkinter (tcl-tk)
when installing python, if tcl-tk
hasn't been installed with brew
beforehand.
The commands below are exactly the same as the aforementioned post, but I've modified each comment to try to make them more newbie-friendly.
Uninstall both,
$ brew uninstall tcl-tk
uninstall tcl-tk with homebrew
$ pyenv uninstall 3.10.4
uninstall current python in pyenv. the last part is the current version of your python, which can be checked with python --version
then reinstall with correct order,
$ brew install tcl-tk
reinstall tcl-tk, version shouldn't need to be specified
$ pyenv install 3.10.4
reinstall Python with pyenv
$ pyenv global 3.10.4
set as global Python version
this problem should go away.
pyenv
or other tools to setup a virtual environment for python, further readings can be seen here.Upvotes: 6
Reputation: 3463
This worked for me in pycharm on Monterey.
Installed python3.10
Then go to: Preferences
Upvotes: 1
Reputation: 101
Thanks to @typedecker
Issue was with Python 3.8 and the Monterey update.
Fix:
First install Python 3.10 then follow this tutorial:
Creating Python 3.10 Virtual Env
Then simply select the newly created virtual env in PyCharms and run.
Upvotes: 4