Takusui
Takusui

Reputation: 175

How to remove popup title in kivy

I've been wondering if there is a way to remove the title bar of a popup window:

From this

To this

Thanks in advance!

Edit: Code reference for future use:

<MyPopup@Popup>:
size_hint: None, None
size: 300, 200
title: 'Close'
title_color: 0.7, 0, 0, 0.9
separator_color: 0.4, 0.4, 0.4, 1
title_align: 'center'
BoxLayout:
    orientation: 'vertical'
    padding: 5, 5, 5, 5
    cols: 2
    Label:
        color: 0.7, 0, 0, 0.9
        center_x: root.center_x
        center_y: root.center_y
        text: 'Are you sure you want to exit?'
    BoxLayout:
        size_hint: 1, 0.6
        Button:
            color: 0.7, 0, 0, 0.9
            background_color: 0.4, 0.4, 0.4, 0.05
            text: 'Yes'
            on_release: exit()
        Button:
            color: 0.7, 0, 0, 0.9
            background_color: 0.4, 0.4, 0.4, 0.05
            text: 'No'
            on_release: root.dismiss()

Upvotes: 5

Views: 3413

Answers (2)

inclement
inclement

Reputation: 29458

Use a ModalView instead. This is the base class for popup-style behaviour, Popup is a ModalView with the title added.

Upvotes: 6

FJSevilla
FJSevilla

Reputation: 4513

You only need to set title property to "" and separator_height property to 0:

Example:

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.popup import Popup
from kivy.lang import Builder


Builder.load_string("""

<NoTitleDialog>:
    title: ""                 # <<<<<<<<
    separator_height: 0       # <<<<<<<<
    size_hint: None, None
    size: 400, 200

    BoxLayout:
        orientation: "vertical"
        Label:
            text: "Are you sure you want to exit?"
        BoxLayout: 
            size_hint_y: 0.3   
            Button:
                text: "Yes"
            Button:
                text: "No"

""")


class MainWindow(BoxLayout):
    def __init__(self, **kwargs):
        super(MainWindow, self).__init__(**kwargs)
        self.dialog = NoTitleDialog()
        self.dialog.open()


class NoTitleDialog(Popup):
    pass


class Example(App):
    def build(self):
        return MainWindow()

if __name__ == '__main__':
    Example().run()

enter image description here

Upvotes: 6

Related Questions