-
Notifications
You must be signed in to change notification settings - Fork 0
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
MAC: Command Window Button Background Colors Do Not Show #51
Comments
import tkinter as tk
from tkmacosx import Button
def on_enter(e):
button.config(bg='blue')
def on_leave(e):
button.config(bg='red')
root = tk.Tk()
button = Button(root, text="Hover Me")
button.pack(pady=20)
button.bind("<Enter>", on_enter)
button.bind("<Leave>", on_leave)
root.mainloop() |
Excellent! The GF4 code involved in the file cmdwin.py. This can be run as a standalone window. If you are going to try working with the code, please read https://github.com/tbpassin/gf4-project/blob/devel/DEVELOPERS_READ_THIS.md first. My first thought is to change the import
(some of this is left over from when GF4 used to support both Python 2.7 and 3.x. I can never remember which branch is for which, so I've just left both alternatives in. I could change these conditional imports and maybe I should finally do it). I don't know if these statements would work with tkmaxosx or not. If not, we would have to make more elaborate code changes (probably not much more complex, though). What would be especially good is if tkmacosx would also work on Windows and Linux. I will try it in a venv. The code that dynamically changes the button background color is in the function definitions |
Here is a minimal program that opens a Tk window and displays a button that changes color when hovered. It uses the same techniques as GF4's cmd.py button window.
This code works as expected on Windows and Linux. Although on Linux, the background color is the system default, not the one specified in the code. Changing |
A user with a Macintosh reports that command buttons do not change their background colors when moused over. The color is used for several purposes, including indicating that extended help messages are available.
Without a Mac to test with, this will be hard to diagnose. With one it might be possible depending on Tk and its quirks on the Mac.
See https://stackoverflow.com/questions/72056706/tkinter-button-background-color-is-not-working-in-mac-os
https://www.reddit.com/r/learnpython/comments/npdwsp/tkinter_button_color_wont_change/
tkmacosx is pip-installable. The project is at
https://pypi.org/project/tkmacosx/
It looks like it might do the job for very little code change. Of course, A Mac is needed for testing.
The text was updated successfully, but these errors were encountered: