G
G
Guerro692020-05-19 20:15:34
Python
Guerro69, 2020-05-19 20:15:34

Python kivy, possible to make button color change on hover?

Is it possible to change the color of a button on hover like it is possible in Qt5.
If it can be done, then how?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
U
Umpiro, 2020-05-20
@Umpiro

It is possible like this:

from kivy.uix.button import Button
from kivy.core.window import Window

class HLButton(Button):

    def __init__(self, *args, **kwargs):
        super(HLButton, self).__init__(*args, **kwargs)
        Window.bind(mouse_pos=self.pos_check)

    def pos_check(self, inst, pos):
        if self.collide_point(*pos):
             self.background_color = (1, 0, 0, 1)
        else:
             self.background_color = (.52, .43, .57, 1)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question