4

I'm learning Tkinter right now and trying to work through my first issue, but finding Google hasn't been helpful.

I'm running this code on Mac OS X 10.15.1 (Catalina)

I'm using Python 3.7 and my code looks like so (lots of boilerplate per PEP8 standards):

"""
Experiments in tkinter
"""


import tkinter as tk


def main():
    """
    Main entrypoint
    """

    tk._test()


if __name__ == "__main__":
    main()

This outputs the following warning to the console:

DEPRECATION WARNING: The system version of Tk is deprecated and may be removed in a future release. Please don't rely on it. Set TK_SILENCE_DEPRECATION=1 to suppress this warning.

It also displays a window with completely blank buttons:

Output of <code>tkinter._test()</code>

From my understanding these buttons should say "Click Me" and "Quit".

Also when I click on the top button it flashes black for a second like so:

Result of clicking on first button

After which the button is wider than before:

Clicking twice Clicking ten times

I assume the Tk version error may be related to the output behavior. However I can't seem to find a way to update Tk. What should I do here?

Update

After seeing @ShayneLoyd's answer (suggesting I needed an updated version of Python with an updated version of Tk) I began looking around some more and found this post on the Apple Discussion Boards which suggests you can use homebrew to install a version of Python which link's homebrew's own installed version of Tk. I tried this and it failed, so I Google'd the issue and found this StackOverflow post which seemed to suggest I can install ActiveTcl and it will work.

I installed ActiveTcl from ActiveState and went back to my project. At first, I ran it like so:

$> cd ~/Source/experiments/python/tkinter
$> ./test.py

This actually worked! I could read the buttons and it behaved like it should. Then I realized I was not using pipenv, so I did a quick test:

$> pipenv run ./test.py

Now I was back to the failure state. I updated my script to display the Tcl and Tk version and sure enough when I used pipenv it was loading Tcl/Tk 8.5.9 but when I didn't use pipenv it was loading 8.6.9

So how do I fix pipenv now?

stovfl
  • 14,998
  • 7
  • 24
  • 51
stevendesu
  • 15,753
  • 22
  • 105
  • 182
  • I can not replicate your error. I don't understand why you need `tkinter._test()` to work because you never use it either – Hippolippo Nov 07 '19 at 15:51
  • 1
    I want `tkinter._test()` to work because I'm using `tkinter` for the first time and this is like the `tkinter` version of "Hello, World". If this doesn't work, I need to fix my development environment. As for the "because you never use it", I don't know what you're saying -- I clearly ***do*** use it, right there in my code - and the window I have several screenshots of is the result. – stevendesu Nov 07 '19 at 16:01
  • Are you on OSX? I think this is a bug on OSX. If you resize the window, the text on the buttons will probably appear. – Bryan Oakley Nov 07 '19 at 16:04
  • @BryanOakley This is OS X (10.15.1 Catalina, specifically). Although resizing the window did not fix the buttons. – stevendesu Nov 07 '19 at 16:06
  • Old habits die hard... it's actually macOS now, not OS X ;) – ThinkingInBits Apr 10 '20 at 01:00

2 Answers2

6

For anyone who's having the same issue and cannot switch Python version, you can easily bypass the "not showing text on buttons" problem by changing MacOs theme. System Preferences>General>Light Mode.

You should have in mind that you may encounter other problems.

Community
  • 1
  • 1
Alesof
  • 321
  • 2
  • 8
4

After a few hours messing with it I figured it out!

The Pipfile contained a reference to Python version 3.7

Therefore pipenv install was searching my machine for any 3.7 version of Python installed. The version it found was Homebrew's, which has Tk 8.5.9 statically linked.

By updating the Pipfile to require Python 3.8 my machine started pulling my system Python, which uses the dynamically linked Tk, which I had successfully updated to 8.6.9

stevendesu
  • 15,753
  • 22
  • 105
  • 182
  • it works like a charm !!, Just to be clear in the steps what I did was, 1) install python 3.8.2 from python.org, 2) install ActiveTcl as you mentioned before, 3) create the Pipenv env using "pipenv --python 3.8.2". if you create the env just with "pipenv install" it will use the old tcl/tk version. – Manuel Felipe Garcia Rincon Apr 03 '20 at 23:46