Can't change the colour of Tk button text - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: Can't change the colour of Tk button text (/thread-16404.html) |
Can't change the colour of Tk button text - Pilover - Feb-26-2019 Please help! This code doesn't work, but doesn't produce an error. from tkinter import * master = Tk() button = Button(master, text="some text", bg="red") button.grid(column=0, row=0) This code is a simplified version of some code I'm using in a much bigger project. I am using Python 3 on a Mac and Raspberry Pi. The colour change option doesn't seem to work on the Mac or the Pi for buttons, but does for labels, etc., . RE: Can't change the colour of Tk button text - Larz60+ - Feb-26-2019 with ttk you can use a style command, can't remember if this works with plain tkinter, you'll have to check. But, with plain tkinter you can change background and foreground colors to get same effect, example: >>> import tkinter >>> root = tkinter.Tk() >>> xx = tkinter.Button(root, text='Hello', bg="white", fg="blue") >>> xx.pack() >>> root.mainloop() RE: Can't change the colour of Tk button text - Pilover - Feb-27-2019 Thank you for your response. I've tried your example code and that doesn't seem to work either. RE: Can't change the colour of Tk button text - Larz60+ - Feb-27-2019 I tried it, and indeed it does work. if you need it in a file to try, create a file named trycolor.py and place this code in the file: trycolor.py: import tkinter root = tkinter.Tk() xx = tkinter.Button(root, text='Hello', bg="white", fg="blue") xx.pack() root.mainloop()Then run it (from command line) using: python trycolor.py RE: Can't change the colour of Tk button text - Pilover - Feb-27-2019 ah, a bit more experimenting.. it does work on my Pi, but not on my Mac.. RE: Can't change the colour of Tk button text - GaryMBloom - Nov-15-2022 (Feb-27-2019, 09:02 PM)Pilover Wrote: ah, a bit more experimenting.. it does work on my Pi, but not on my Mac.. This failure of Tkinter Buttons to have their color changed on Mac is a well-known and long-standing issue. It's only for Buttons, not Labels. I wrote a project called TTWidgets which supports multi-font, multi-color, multi-image Buttons and Labels. It's based on the Label widget, so it works around the MacOS Button color issue. Check out https://pypi.org/project/ttwidgets/ from ttwidgets import TTButton The TTButton API is a superset of the Tkinter.Button API. RE: Can't change the colour of Tk button text - woooee - Nov-15-2022 There is also CustomTkinter, which is close to the tkinter widgets. Note that bg in tkinter is fg in customtkinter, and fg is text_color. |