Make sci-fi-like buttons with Kivy

Completed

I made it with Kivy thinking that I could make a SF-like button without using images. As a result, a button like this was created. SFButton.JPG

That's why I made it

The policy is simple and is achieved by creating two frames on the button canvas. If you run main.py and test.kv in the same hierarchy, it will look like the first image.

main.py


from kivy.app import App
from kivy.factory import Factory

class TestApp(App):
    def __init__(self, **kwargs):
        super(TestApp, self).__init__(**kwargs)
        
    def build(self):
        self.root = root = Factory.FloatLayout()

        btn = Factory.SFButton(
            text="This is SF !",
            size_hint=(0.5, 0.2),
            pos_hint={'x':0.25, 'y':0.4},
            on_release=self.btn_pushed
        )
        root.add_widget(btn)
        
        return root
    
    def btn_pushed(self, instance, *args):
        print(f"{instance.text} pushed !")


def main():
    TestApp().run()

if __name__ == '__main__':
    main()

test.kv


#: import hex kivy.utils.get_color_from_hex

<SFButton@Button>:
    background_color: hex('#44acac')
    canvas.before:
        Color:
            rgba: hex('#26c7e5')
        Line:
            width: 2
            rectangle: self.x, self.y, self.width, self.height

        Color:
            rgba: hex('#26c7e5')
        Line:
            width: 1
            rectangle: self.x-4, self.y-4, self.width+8, self.height+8

point

In canvas.before, you can draw a picture by specifying the color → specifying the figure continuously. Using that, the rectangle is drawn in the order of inside → outside. When you draw the outer line here, just like the inner line

rectangle: self.x, self.y, self.width, self.height

If you do ... failed.JPG And like this, only the inner line can be seen. (Why isn't it overwritten by the outer line ??) Therefore, on the outer line

rectangle: self.x-4, self.y-4, self.width+8, self.height+8

I adjusted it so that it becomes a slightly larger rectangle. I think this side will change again with the width of the outer line. By the way

rectangle: self.x-3, self.y-3, self.width+6, self.height+6

In the case of ex2.JPG have become. I tried various other things, but personally I like the adjustment of test.kv which is the image at the beginning.

I think it is easier to see the color specification in hexadecimal, so I use the kivy.utils.get_color_from_hex function.

Finally

I think I was able to get a good feeling without the image. In the end, I want to operate with a SF-like design even when pressed,

Recommended Posts

Make sci-fi-like buttons with Kivy
GUI programming with kivy ~ Part 4 Various buttons ~
Make a drawing quiz with kivy + PyTorch
Make a Yes No Popup with Kivy
GUI programming with kivy ~ Part 5 Creating buttons with images ~
Make Lambda Layers with Lambda
Make Yubaba with Discord.py
Make slides with iPython
Getting Started with Tkinter 2: Buttons
Let's make Othello with wxPython
Easy to make with syntax
Make Puyo Puyo AI with Python
Let's make dice with tkinter
Make a fortune with Python
Make a fire with kdeplot
Make Slack chatbot with Errbot
Make Echolalia LINEbot with Python + heroku
Make ASCII art with deep learning
Let's make a GUI with python.
Make a sound with Jupyter notebook
Let's make a breakout with wxPython
Let's make Othello AI with Chainer-Part 1-
Make testing with Selenium more accessible
Make a recommender system with python
Async / await with Kivy and tkinter
Make compute server diskless with LTSP
Make a filter with a django template
Let's make a graph with python! !!
Let's make a supercomputer with xCAT
Let's make Othello AI with Chainer-Part 2-
Make a model iterator with PySide
Make people smile with Deep Learning
Make Scrapy an exe with Pyinstaller
Make a nice graph with plotly