Skip to content

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

Closed
terryjreedy opened this issue May 27, 2021 · 11 comments
Closed

tkinter button colors on Mac #88409

terryjreedy opened this issue May 27, 2021 · 11 comments
Labels
3.9 only security fixes 3.10 only security fixes 3.11 only security fixes OS-mac topic-tkinter type-bug An unexpected behavior, bug, or error

Comments

@terryjreedy
Copy link
Member

BPO 44243
Nosy @rhettinger, @terryjreedy, @ronaldoussoren, @taleinat, @ned-deily, @roseman, @serhiy-storchaka, @E-Paine

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:

assignee = None
closed_at = <Date 2021-05-28.01:03:09.665>
created_at = <Date 2021-05-27.01:56:01.931>
labels = ['OS-mac', 'type-bug', 'expert-tkinter', '3.9', '3.10', '3.11']
title = 'tkinter button colors on Mac'
updated_at = <Date 2021-05-28.01:03:09.665>
user = 'https://github.com/terryjreedy'

bugs.python.org fields:

activity = <Date 2021-05-28.01:03:09.665>
actor = 'terry.reedy'
assignee = 'none'
closed = True
closed_date = <Date 2021-05-28.01:03:09.665>
closer = 'terry.reedy'
components = ['macOS', 'Tkinter']
creation = <Date 2021-05-27.01:56:01.931>
creator = 'terry.reedy'
dependencies = []
files = []
hgrepos = []
issue_num = 44243
keywords = []
message_count = 11.0
messages = ['394506', '394513', '394521', '394522', '394526', '394534', '394585', '394586', '394596', '394598', '394618']
nosy_count = 8.0
nosy_names = ['rhettinger', 'terry.reedy', 'ronaldoussoren', 'taleinat', 'ned.deily', 'markroseman', 'serhiy.storchaka', 'epaine']
pr_nums = []
priority = 'normal'
resolution = 'third party'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue44243'
versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']

@terryjreedy
Copy link
Member Author

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?)

@terryjreedy terryjreedy added 3.9 only security fixes 3.10 only security fixes 3.11 only security fixes OS-mac topic-tkinter labels May 27, 2021
@taleinat
Copy link
Contributor

FWIW this also behaves as expected on Ubuntu 20.04 with both Python 3.8 and 3.10.

@taleinat
Copy link
Contributor

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

@taleinat
Copy link
Contributor

I've created an issue about this on the Tcl/Tk issue tracker:

https://core.tcl-lang.org/tk/tktview/46274a117823fd65c6d98d38465b43165d0c4680

@E-Paine
Copy link
Mannequin

E-Paine mannequin commented May 27, 2021

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()

@taleinat
Copy link
Contributor

Thanks for helping with this, E. Paine!

Unfortunately, no, adding activebackground='red' doesn't help, even directly in a wish shell.

@taleinat
Copy link
Contributor

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."

@taleinat
Copy link
Contributor

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".

@terryjreedy
Copy link
Member Author

"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.

@terryjreedy terryjreedy added type-bug An unexpected behavior, bug, or error labels May 27, 2021
@terryjreedy
Copy link
Member Author

bpo-44254 is a followup to change turtledemo unpressed button colors to something on white.

@roseman
Copy link
Mannequin

roseman mannequin commented May 27, 2021

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.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
@terryjreedy terryjreedy closed this as not planned Won't fix, can't repro, duplicate, stale Oct 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.9 only security fixes 3.10 only security fixes 3.11 only security fixes OS-mac topic-tkinter type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants