Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to change button background color while clicked tkinter python

#Type "activebackground=" + your chosen background color between commas
col = Button(yourWindow, text='col', bg='gray25', activebackground='cyan')
Comment

tkinter button foreground color click

# use activebackground and activeforeground properties to change the 
# button color at the instance of being pressed.
btn = Button(frame, text="Click me", activebackground="blue",
             activeforeground="white")
# activebackground will change the background of the button when clicked
# activeforeground will change the text color of the button when clicked
Comment

python button tkinter change color

def fade(widget, smoothness=4, cnf={}, **kw):
    """This function will show faded effect on widget's different color options.

    Args:
        widget (tk.Widget): Passed by the bind function.
        smoothness (int): Set the smoothness of the fading (1-10).
        background (str): Fade background color to.
        foreground (str): Fade foreground color to."""

    kw = tk._cnfmerge((cnf, kw))
    if not kw: raise ValueError("No option given, -bg, -fg, etc")
    if len(kw)>1: return [fade(widget,smoothness,{k:v}) for k,v in kw.items()][0]
    if not getattr(widget, '_after_ids', None): widget._after_ids = {}
    widget.after_cancel(widget._after_ids.get(list(kw)[0], ' '))
    c1 = tuple(map(lambda a: a/(65535), widget.winfo_rgb(widget[list(kw)[0]])))
    c2 = tuple(map(lambda a: a/(65535), widget.winfo_rgb(list(kw.values())[0])))
    colors = tuple(colour.rgb2hex(c, force_long=True)
                   for c in colour.color_scale(c1, c2, max(1, smoothness*100)))

    def worker(count=0):
        if len(colors)-1 <= count: return
        widget.config({list(kw)[0] : colors[count]})
        widget._after_ids.update( { list(kw)[0]: widget.after(
            max(1, int(smoothness/10)), worker, count+1) } )
    worker()
#source: https://stackoverflow.com/questions/49433315/is-there-a-wayor-a-library-for-making-a-smooth-colour-transition-in-tkinter
Comment

how to set background color for a button in tkinter

from tkinter import *
root = Tk()
button = Button(root, bg='red')  # Background color = red
button.pack()
root.mainloop
Comment

PREVIOUS NEXT
Code Example
Python :: pandas index to list 
Python :: how to get all file names in directory python 
Python :: python how to unnest a nested list 
Python :: insta profile downloader in python 
Python :: pyspark find columns with null values 
Python :: install auto-py-to-exe 
Python :: send email python 
Python :: zipfile python 
Python :: load ui file pyqt5 
Python :: pandas read csv without header 
Python :: how to start ftpd server with python 
Python :: click js selenium python 
Python :: pyqt5 wait cursor 
Python :: python program to print list vertically without using loop 
Python :: get eth balance python 
Python :: python load pandas from pickle 
Python :: python use .env 
Python :: python paramiko check ssh connection 
Python :: random numbers in python 
Python :: ndarray to list 
Python :: python f string decimal places 
Python :: python iterate object 
Python :: python cv2 resize keep aspect ratio 
Python :: python pandas change column values to all caps 
Python :: python detect keypress 
Python :: python shortest path of list of nodes site:stackoverflow.com 
Python :: keras ensure equal class representation during traingin 
Python :: matplotlib random color 
Python :: to_dataframe pandas 
Python :: copy file in python3 
ADD CONTENT
Topic
Content
Source link
Name
3+4 =