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
#1
I'm trying to get a "Save" button color to change color if any form data has been changed. I got this to work once before but misplaced my flash drive with it on there. Current attempts are failing. Any pointers? There's an unseen module which talks to the database which I don't think will make a difference here. The code I'm referring to is down towards the bottom. Thanks in advance:

from tkinter import *
from tkinter import ttk
import tkinter as tk
import dbConnect as db

db.ssConnect()


rowspacer=40
colspacer=40

class demoForm():

    def fillDemoForm():
        root = Tk()
        fName = tk.StringVar().trace_add('write',demoForm.changeButton)
        lName = tk.StringVar().trace_add('write',demoForm.changeButton)    
        fName = db.getFlds.getFld(index=0,fldName='Fname',tblName='Name2')
        lName = db.getFlds.getFld(index=0,fldName='Lname',tblName='Name2')

        

        btnSave = ttk.Button(text="Save")
        btnSave.place(x=colspacer*6, y=rowspacer*1)

        lblFname= tk.Label(text='fName').place(x=10, y=10)
        fldFname = Entry(root,textvariable=fName )
        fldFname.place(x=60, y= 10)
        fldFname.delete(0,END)
        fldFname.insert(0,fName)

        lblLname= tk.Label(text='lName').place(x=10, y=rowspacer)
        fldLname= tk.Entry(root, textvariable=lName)
        fldLname.place(x=60, y= rowspacer)
        fldLname.delete(0,END)
        fldLname.insert(0,lName)

        root.geometry('325x250')
        root.configure(background = "lightgray")

        root.mainloop()

    def changeButton():
        btnSave=Button(root, text="Save",bg="red")

demoForm.fillDemoForm()
pymn likes this post
Reply


Messages In This Thread
Can't get tkinter button to change color based on changes in data - by dford - Feb-12-2022, 11:24 PM

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