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
  [PyQt] Python PyQt5 - Change label text dynamically based on user Input ppel123 1 105 Mar-20-2020, 07:21 AM
Last Post: deanhystad
  change background color of button ieee488 3 2,538 Jul-30-2019, 09:49 PM
Last Post: ieee488
  [PySimpleGui] How to alter mouse click button of a standard submit button? skyerosebud 3 664 Jul-21-2019, 06:02 PM
Last Post: FullOfHelp
  Text after push button chano 13 985 Jul-05-2019, 03:10 PM
Last Post: Yoriz
  [Tkinter] changing the frame colour nick123 2 1,626 May-14-2019, 02:48 PM
Last Post: nick123
  How to change the text in label? ;/ Dzonzi 3 14,251 Jul-18-2018, 07:26 PM
Last Post: nilamo
  Set input text from button gio123 1 1,107 Mar-01-2018, 10:28 AM
Last Post: gio123
  [Tkinter] Selected radio button in push button in Tkinter prashantfunde91 1 7,416 Jun-22-2017, 05:27 PM
Last Post: DeaD_EyE
  [Tkinter] Problem with changing label text on button press xk2006x 1 3,253 Jun-02-2017, 06:00 PM
Last Post: nilamo
  PyGTK3, I can't Change Button and Table Backgorund Color using modify_bg method. harun2525 3 4,486 Apr-24-2017, 04:05 PM
Last Post: changos

Forum Jump:


Users browsing this thread: 1 Guest(s)