-
-
Notifications
You must be signed in to change notification settings - Fork 32k
tkinter button colors on Mac #88409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Mac Mohave, 3.9 with 8.6.8 and 3.10 with 8.6.11 import tkinter as tk
r = tk.Tk()
b = tk.Button(r, text='START', fg='white', bg='red') # Or '#f00'.
b.pack()
r.mainloop() On Windows, white on red button, as expected. On Mac, all white until one presses and holds mouse, and then blue background. Default black on white works OK. This may be new since several years ago, when 2 of us worked on turtle demo, which has 3 such buttons. They all now misbehave (reported by Raymond). If someone tested on Mac, it must have worked then. I retried with the b= line replaced with s = ttk.Style()
s.configure('Td.TButton', foreground='white', background='red')
b = ttk.Button(r, text='START', style='Td.TButton') with the same result. (Mark, did I get this right?) |
FWIW this also behaves as expected on Ubuntu 20.04 with both Python 3.8 and 3.10. |
Confirmed on macOS. This bugs also affects the underlying Tcl/Tk, confirmed with 8.6.11. To reproduce: $ wish
% button .b -text START -bg red -fg white
.b
% pack .b |
I've created an issue about this on the Tcl/Tk issue tracker: https://core.tcl-lang.org/tk/tktview/46274a117823fd65c6d98d38465b43165d0c4680 |
Does the activebackground option fix this? E.g. r = tk.Tk()
b = tk.Button(r, fg="white", bg="red", activebackground="red")
b.pack()
r.mainloop() |
Thanks for helping with this, E. Paine! Unfortunately, no, adding activebackground='red' doesn't help, even directly in a wish shell. |
The Tcl/Tk devs have closed the issue I opened on their issue tracker as "not a bug", with the following comment: "Because Tk on the Mac uses API's to draw buttons, some configuration options are set by the OS and not by Tk. This is documented in the button man page: "On Aqua/Mac OS X, some configuration options are ignored for the purpose of drawing of the widget because they would otherwise conflict with platform guidelines. The configure and cget subcommands can still manipulate the values, but do not cause any variation to the look of the widget. The options affected notably include -background and -relief." Closing this ticket as not a bug." |
It appears that this behavior is the intended behavior of Tk on macOS. Given that tkinter is meant to be a relatively straightforward wrapping of Tcl/Tk, it seems to me that we too should consider this not to be a bug, and resolve this issue as "won't fix". |
"The configure and cget subcommands can still manipulate the values, but do not cause any variation to the look of the widget." is wrong. Setting the foreground color *does* change the unpressed foreground color, so that 'white' becomes 'white on white'. I consider not being more explicit about which options are or or not fixed, or at least not warning about foreground, to be a doc buglet. What a trap for someone trying to make a cross-platform dark theme. But their docs are theirs. And our docs are ours. We can't change external tk or ttk docs, but how about adding the following to the our ttk doc, just above 'Combobox'? Button On macOS, the pressed colors are fixed as white on blue. The background is otherwise fixed as white. So an attempt at white on dark results in white on white. |
bpo-44254 is a followup to change turtledemo unpressed button colors to something on white. |
Let it go. Changing the Python docs to a behaviour that isn't guaranteed by the underlying library is a virtual guarantee that a later version of Tk (or even the way the API it uses behaves on another version of macOS) will have some other (unrelated) modifications that change the current behaviour to something else. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: