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
  How to make button text bold in Tkinter? scratchmyhead 2 126 May-16-2020, 02:53 AM
Last Post: scratchmyhead
  [Tkinter] Python 3 change label text gw1500se 6 698 May-08-2020, 05:47 PM
Last Post: deanhystad
  [Tkinter] Text Button - How Do I Reduce The Margin? vman44 6 229 Apr-27-2020, 10:48 PM
Last Post: Larz60+
  [PyQt] Python PyQt5 - Change label text dynamically based on user Input ppel123 1 495 Mar-20-2020, 07:21 AM
Last Post: deanhystad
  change background color of button ieee488 3 3,360 Jul-30-2019, 09:49 PM
Last Post: ieee488
  [PySimpleGui] How to alter mouse click button of a standard submit button? skyerosebud 3 866 Jul-21-2019, 06:02 PM
Last Post: FullOfHelp
  Text after push button chano 13 1,169 Jul-05-2019, 03:10 PM
Last Post: Yoriz
  [Tkinter] changing the frame colour nick123 2 2,346 May-14-2019, 02:48 PM
Last Post: nick123
  How to change the text in label? ;/ Dzonzi 3 16,370 Jul-18-2018, 07:26 PM
Last Post: nilamo
  Set input text from button gio123 1 1,245 Mar-01-2018, 10:28 AM
Last Post: gio123

Forum Jump:


Users browsing this thread: 1 Guest(s)