Python Forum
Can't get tkinter button to change color based on changes in data
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can't get tkinter button to change color based on changes in data
#4
import tkinter as tk

root = tk.Tk()
root['padx'] = 8
root['pady'] = 5

my_var = tk.StringVar()
my_var2 = tk.StringVar()

label = tk.Label(root, text='fName')
label.grid(column=0, row=0, sticky='new', pady=2)

entry = tk.Entry(root, textvariable=my_var)
entry.grid(column=1, row=0, sticky='new', pady=2)
entry.insert(0, 'john')

label2 = tk.Label(root, text='lName')
label2.grid(column=0, row=1, sticky='new', pady=2)

entry2 = tk.Entry(root, textvariable=my_var2)
entry2.grid(column=1, row=1, sticky='new', pady=2)
entry2.insert(0, 'doe')

btn = tk.Button(root, text='Save')
btn.grid(column=0, row=2, columnspan=2, sticky='ew', pady=2)

def callback(var, index, mode):
    btn.configure(bg='red')

my_var.trace_add('write', callback)
my_var2.trace_add('write', callback)

root.mainloop()
BashBedlam likes this post
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply


Messages In This Thread
RE: Can't get tkinter button to change color based on changes in data - by menator01 - Feb-13-2022, 06:35 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] TKinter Remove Button Frame Nu2Python 8 1,604 Jan-16-2024, 06:44 PM
Last Post: rob101
  tkinter - touchscreen, push the button like click the mouse John64 5 1,196 Jan-06-2024, 03:45 PM
Last Post: deanhystad
  Centering and adding a push button to a grid window, TKinter Edward_ 15 6,305 May-25-2023, 07:37 PM
Last Post: deanhystad
  [Tkinter] Trying to add data into a shelf from a submit button TWB 8 2,127 Jan-06-2023, 11:30 PM
Last Post: TWB
  Can't change the colour of Tk button text Pilover 6 15,618 Nov-15-2022, 10:11 PM
Last Post: woooee
  [PyQt] [Solved]Change text color of one line in TextBrowser Extra 2 5,321 Aug-23-2022, 09:11 PM
Last Post: Extra
  [Tkinter] Tkinter don't change the image DQT 2 1,920 Jul-22-2022, 10:26 AM
Last Post: menator01
  [WxPython] [SOLVED] How to change button label? Winfried 3 2,321 May-31-2022, 06:37 PM
Last Post: Winfried
  Tkinter - How can I change the default Notebook border color? TurboC 5 15,246 May-23-2022, 03:44 PM
Last Post: bigmac
Question [Tkinter] Change Treeview column color? water 3 10,251 Mar-04-2022, 11:20 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