Josh Bloom
Josh Bloom

Reputation: 167

Is it possible to make a button transparent (Kivy)

Is it possible to make a Button transparent in Kivy?

Just for reference here is the code of the page:

class home(Screen):

def __init__(self,**kwargs):
    super (home,self).__init__(**kwargs)

    bkg = GridLayout(cols = 1)
    i = Image(source='/Users/User/Downloads/im3.jpg',y = bkg.height)
    bkg.add_widget(i)
    my_box1 = BoxLayout(orientation='vertical')
    my_button1 = Button(text="Run tests",size_hint_y=None, size_y=100)
    my_button2 = Button(text="View VG images",size_hint_y=None, size_y=100)
    my_button3 = Button(text="View test logs",size_hint_y=None, size_y=100)
    my_button1.bind(on_press=self.run)
    my_button2.bind(on_press=self.vg)
    my_button3.bind(on_press=self.logs)
    my_box1.add_widget(my_button1)
    my_box1.add_widget(my_button2)
    my_box1.add_widget(my_button3)
    self.add_widget(bkg)
    self.add_widget(my_box1)

def run(self,*args):
    self.manager.current = 'RunTests'
def vg(self,*args):
    self.manager.current = 'vgMenu'
def logs(self,*args):
    self.manager.current = 'logs'

Upvotes: 3

Views: 9815

Answers (1)

Peter Badida
Peter Badida

Reputation: 12179

Of course it is! Just use the background_color and for the text use color.

If you use the shape of 4 digits, then it's the RGBA mode i.e. you can set the alpha for the color too, therefore you can make it transparent:

from kivy.lang import Builder
from kivy.base import runTouchApp
runTouchApp(Builder.load_string('''
BoxLayout:
    canvas:
        Color:
            rgba: 1, 0, 0, 1
        Rectangle:
            size: self.size
            pos: self.pos
    Button:
        background_color: 0, 0, 0, 0
        text: 'blob'
'''))

Upvotes: 5

Related Questions