GawronDev
GawronDev

Reputation: 137

Is it possible to add a logo to KivyMD Toolbar?

I'm writitng an app using KivyMD. Is it possible to add a logo to the MDToolbar class? I want the logo to be in the center and have two buttons on its left and right. I tried using the Image and canvas class but it didnt work out...

Upvotes: 1

Views: 2258

Answers (1)

Fadi Abu Raid
Fadi Abu Raid

Reputation: 841

What you want is 2 buttons and a canvas at the center of the toolbar I guess. This is how you can achieve it.

Python code

from kivy.lang import Builder
from kivymd.app import MDApp
from kivy.core.window import Window
KV = '''
BoxLayout:
    orientation: "vertical"
    
    MDToolbar:
        id: layout
        title: "MDToolbar"
        canvas:
            Rectangle:
                source: 'logo.jpg'
                pos: (((self.parent.size[0])/2)-30,self.pos[1])
                size: (60, 60)
        Button:
            text: ''
            pos: (((self.parent.size[0])/2)+60,self.pos[1])
            background_normal: 'right.png'
            background_down: 'right.png'
            size_hint: None, None 
            size: (60, 60)
            on_press: print("right")
            on_release: print("right")
            border: (0,0,0,0)
        Button:
            text: ''
            pos: (((self.parent.size[0])/2)-120,self.pos[1])
            background_normal: 'left.png'
            background_down: 'left.png'
            size_hint: None, None 
            size: (60, 60)
            on_press: print("left")
            on_release: print("left")
            border: (0,0,0,0)
 
    MDLabel:
        text: "Content"
        halign: "center"
'''


class Test(MDApp):
    def build(self):
        return Builder.load_string(KV)

Window.show_cursor = True

Test().run()

Output enter image description here

Upvotes: 2

Related Questions