Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Can't change the colour of Tk button text
#1
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., .
Quote
#2
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()
Quote
#3
Thank you for your response.
I've tried your example code and that doesn't seem to work either.
Quote
#4
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
Quote
#5
ah, a bit more experimenting.. it does work on my Pi, but not on my Mac..
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  [tkinter] color change for hovering over button teacher 4 108 Jul-04-2020, 06:33 AM
Last Post: teacher
  [PyQt] Increase text size and change color based on temp pav1983 5 152 Jun-22-2020, 10:52 PM
Last Post: menator01
  How to make button text bold in Tkinter? scratchmyhead 2 205 May-16-2020, 02:53 AM
Last Post: scratchmyhead
  [Tkinter] Python 3 change label text gw1500se 6 797 May-08-2020, 05:47 PM
Last Post: deanhystad
  [Tkinter] Text Button - How Do I Reduce The Margin? vman44 6 313 Apr-27-2020, 10:48 PM
Last Post: Larz60+
  [PyQt] Python PyQt5 - Change label text dynamically based on user Input ppel123 1 801 Mar-20-2020, 07:21 AM
Last Post: deanhystad
  change background color of button ieee488 3 3,670 Jul-30-2019, 09:49 PM
Last Post: ieee488
  [PySimpleGui] How to alter mouse click button of a standard submit button? skyerosebud 3 968 Jul-21-2019, 06:02 PM
Last Post: FullOfHelp
  Text after push button chano 13 1,271 Jul-05-2019, 03:10 PM
Last Post: Yoriz
  [Tkinter] changing the frame colour nick123 2 2,737 May-14-2019, 02:48 PM
Last Post: nick123

Forum Jump:


Users browsing this thread: 1 Guest(s)