Python Forum
[Tkinter] changing background color of a button
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] changing background color of a button
#3
Thanks.

I created a list of buttons as you suggested.

buttons = []
then I add each button to that list
buttons.append(aButton)
But,
buttons[i]['bg'] = 'red'
does not work.
What is the correct syntax that I need to use?

.

Answering my own question.

I did not need
aButton = "button" + str(i)
.

for i in range(1, 3):
    aButton = tkinter.Button(Gui, font=Font1, text=i, image=myPixel, width=70, height=70, compound="c", bg='white', activebackground='white')
    buttons.append(aButton)
    aButton['command'] = partial(setBG, aButton)
    aButton.grid(row=1, column=i)
and add
		buttons[i].config(background="red")
Reply


Messages In This Thread
changing background color of a button - by ieee488 - Sep-06-2019, 11:52 AM
RE: changing background color of a button - by ieee488 - Sep-06-2019, 01:24 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Can't get tkinter button to change color based on changes in data dford 4 3,447 Feb-13-2022, 01:57 PM
Last Post: dford
  [Tkinter] changing and getting value through button niski1996 2 1,834 Aug-24-2021, 04:44 PM
Last Post: niski1996
Question [Tkinter] Can I set background color for each item in tkinter Combobox? water 1 5,137 Dec-10-2020, 07:48 PM
Last Post: Larz60+
  Tkinter - How can I remove the background borders from ttk.Button? TurboC 4 17,095 Oct-18-2020, 10:58 AM
Last Post: TurboC
  tkinter | Button color text on Click Maryan 2 3,402 Oct-09-2020, 08:56 PM
Last Post: Maryan
  [Tkinter] Trying to change font size w/o changing button size python63 3 9,888 Aug-05-2020, 01:04 AM
Last Post: Larz60+
  drawing concentric circles with changing color animation CatherineKan 0 2,452 Jul-05-2020, 03:30 PM
Last Post: CatherineKan
  [tkinter] color change for hovering over button teacher 4 8,578 Jul-04-2020, 06:33 AM
Last Post: teacher
  Restoring Tkinter widget background to original color pythonprogrammer 1 2,986 Dec-16-2019, 04:59 AM
Last Post: woooee
  Make Label Text background (default color) transparent using tkinter in python barry76 1 23,856 Nov-28-2019, 10:19 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020