20

It is very simple program.

import tkinter
tkinter.Button(None, text='button').pack()
tkinter.mainloop()

I expect this program shows me such as a below picture.
work well

But it shows a below picture actually.
not work

When it is resized on GUI it seems working well.

It didn't occur this problem in High Sierra.

My environment is following:

  • macOS Mojave 10.14
  • Python 3.7.0

Could you advice to me?

I found out same problem on here.

martineau
  • 119,623
  • 25
  • 170
  • 301
Tiger
  • 321
  • 2
  • 3
  • I cannot reproduce the problem, however, you can probably either resize your button (not very practical), or try to add a width to it like this: `tkinter.Button(None, text='button', width=8).pack()` - with the value larger than the number of letters in your text. – Reblochon Masque Sep 27 '18 at 04:32
  • Sorry. I sent a message on the way. I added 'width=8' but it doesn't work. As usual the text of the button shows blank. – Tiger Sep 27 '18 at 04:40
  • @ReblochonMasque It is reproduced this problem 100% in my environment. Do I have to provide more information? Please instruct to me :) Thank you for your cooperation. – Tiger Oct 08 '18 at 16:09

11 Answers11

17

Changing Appearance to Light Mode fixed this problem for me.

To change appearance, go to Settings -> General -> Appearance -> Light Mode.

Dark Mode

Light Mode

Pratik Kulkarni
  • 333
  • 3
  • 6
  • 1
    this was my solution for OSX 10.14.5, tkinter 8.5, python 3.7.3 – TabsNotSpaces Jun 03 '19 at 20:20
  • This would also explain my issue using 3.7.3 on 10.14.5 as 8.6.8 also breaks this support, and wasn't fixed until 8.6.9. It also looks like 8.6.9 was added to a Python 2.7.2 test build, but later removed due to regression issues. Updating or downgrading manually can fix this as well. See here: https://stackoverflow.com/questions/55483507/how-to-get-a-black-file-dialog-box-using-tkinter-on-mac-os – DBrown Jul 08 '19 at 02:42
15

I guess there is a bug in Tk. I am on MacOS 10.14.3 If you maximize and minimize the tkinter window the text on the button appears, another solution that worked for me is

from tkinter import *
from tkinter import ttk

button1 = ttk.Button(*your args here*)
Xabnord
  • 209
  • 2
  • 6
  • 1
    Thre's no module `tkk` in `tkinter`. At least in Python 3.7 – manu Feb 18 '19 at 06:41
  • 1
    @manu there is, it is `from tkinter import ttk` or in python 2.7 it is `import ttk` as a separate package. – james-see Feb 24 '19 at 05:38
  • This is what I see in my terminal just now. Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 26 2018, 23:26:24) [Clang 6.0 (clang-600.0.57)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from tkinter import tkk Traceback (most recent call last): File "", line 1, in ImportError: cannot import name 'tkk' from 'tkinter' – manu Feb 24 '19 at 10:35
  • 2
    Using Mojava 10.14.3 and Python 3 3.7.1. I got the same bug, switching my buttons from tk to tkk did the trick. – Michael Porter Mar 24 '19 at 15:23
  • It's actually `ttk.Button`, not `tkk.Button` – JustABit Apr 06 '19 at 13:35
  • 1
    @JustABit Sorry MyBad I will make the changes – Xabnord Apr 06 '19 at 21:50
8

I had this same exact error, and to get it fixed I had to change my buttons to ttk.Button and set a style. For example, add the following to import:

try: from tkinter import ttk # python 3
except: import ttk # python 2.7

And then after the root init:

    style = ttk.Style()
    style.map("C.TButton",
              foreground=[('pressed', 'red'), ('active', 'blue')],
              background=[('pressed', '!disabled', 'black'),
                          ('active', 'white')]
              )

Then when you are instantiating the Button:

self.button = ttk.Button(self, text="my cooool button",
                                 command=self.load_something_cool, style="C.TButton")

It worked perfectly to ensure that the text is displayed properly. Before I added the ttk bit, I was in the same boat as you in Mojave.

james-see
  • 12,210
  • 6
  • 40
  • 47
6

I also had this problem, 100% reproducible on my Mac after upgrading to Mojave and when using Homebrew's python3.

Switching to Python.org 's Python 3.7.1 package download totally eliminated the problem for me.

Jon Garber
  • 61
  • 1
  • 1
    I have updated to python 3.7.1 by using pyenv 1.2.7-11-g835707da. However it doesn't improve not yet. In this version, Label, "button", doesn't appear even if it is resized. But it has been enabled dark mode lol. – Tiger Oct 26 '18 at 10:43
  • Similarly, `conda update -n root conda` then `conda update --all` worked for me (I also ended up needing a separate `conda update spyder` to get Spyder working). – kuzzooroo Nov 28 '18 at 04:17
  • Not working here, Mojave (18B75), `brew upgrade python` and now `python3 --version` returns `3.7.1` but still no fix for tkinter... :( – Mr.Web Dec 09 '18 at 13:45
4

Here's an example that patches up the problem for me (at least until the Python/Tkinter stuff gets cleaned up):

import tkinter
root = tkinter.Tk()
tkinter.Button(root, text='button').pack()
def fix():
    a = root.winfo_geometry().split('+')[0]
    b = a.split('x')
    w = int(b[0])
    h = int(b[1])
    root.geometry('%dx%d' % (w+1,h+1))
root.update()
root.after(0, fix)
tkinter.mainloop()

This was tested on macOS Version 10.14.2 (18C54) and Python 3.7.2 (loaded via Home-brew).

octetta
  • 81
  • 4
  • 1
    This is the proper working solution to this problem, elegant and simple, Should be marked as solution to OP question. – gege Jun 07 '20 at 16:10
  • I probably should have mentioned (in case it's not obvious) that this solution works by making the root window one pixel wider and taller shortly after the mainloop starts. The idea behind this is that resizing the window after starting the app fixes the output, so this code just mimics that behavior via code. – octetta Jun 29 '20 at 23:49
2

I have this problem with an app I wrote and froze with PyInstaller. It still works fine on PC and my Mac laptop that doesn't have Mojave, but on my desktop mac that recently updated to Mojave it has buttons without text, and some buttons are completely invisible until clicked on.

I found an easy solution on Reddit: just resize the window slightly, and the interface elements appear!

Link to Reddit thread

Geoffrey Sametz
  • 618
  • 1
  • 6
  • 17
0

I had this problem only when frozen using py2app. My fix was to use .update_idletasks() on the widget, after all elements are created for each frame or Toplevel.

0

Had the same issue with button text and dropdown text after packaging my program with Pyinstaller. I think its a Tk/Tcl bug. I was able to fix it by entering full screen (green button in grey bar lol) and then minimizing to normal size again (yellow button in grey bar lol).

0

The only viable fix I found for py2app Tkinter windows in Mojave was to update my python version to 2.7.15 (64bit not 64/32bit). Versions prior to this all displayed empty text in the py2app frozen binaries. Directly running the python code displayed fine. Inserting .update_idletasks() prior to the mainloop of each window didn't make a difference for me (tested on two Mojave machines).

nateS
  • 65
  • 6
0

I was having the same problem but now I have fixed it.

If you are using Anaconda, type the following commands in terminal and you should be good to go:

  1. conda update python
  2. conda update anaconda
0

For me it worked to update python to 3.5.6 from 3.5.4.