Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

tkinter change button color smoothly

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

PREVIOUS NEXT
Code Example
Python :: filter query objects by date range in Django 
Python :: Django Abstract base classe 
Python :: how many numbers greater than 100 using pytho 
Python :: cosine similarity python 
Python :: check django channels with redis setup 
Python :: error handling in python 
Python :: PHP echo multiple lines example Using Nowdoc 
Python :: group by dataframe 
Python :: formatted string in python 
Python :: django debug toolbar urlpatterns 
Python :: os dir exists 
Python :: django custom authentication 
Python :: pandas count occurrences of certain value in row 
Python :: how to access a dictionary within a dictionary in python 
Python :: pandas shape 
Python :: Get the first 4 numbers of the innermost arrays using numpy 
Python :: symmetrical sum python 
Python :: compilation terminated. In file included from plugins/python/pyloader.c:1:0: plugins/python/uwsgi_python.h:2:10: fatal error: Python.h: No such file or directory #include <Python.h 
Python :: inherit functions from other classes 
Python :: pandas define how you want to aggregate each column 
Python :: python print exection type 
Python :: os.path.dirname(__file__) 
Python :: Add New Column to Pandas from Dictionary 
Python :: snakeviz python profile 
Python :: django base path on level up 
Python :: legend ax matplotlib 
Python :: check file existtnece python 
Python :: how to find pdf file in link beautifulsoup 
Python :: remove grid in imshow 
Python :: inicio programacao python 
ADD CONTENT
Topic
Content
Source link
Name
9+6 =