如何删除kivy中的弹出标题

时间:2018-01-01 15:23:47

标签: python kivy

我一直想知道是否有办法删除弹出窗口的标题栏:

从此

到此

提前致谢!

编辑:代码参考以供将来使用:

<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()

2 个答案:

答案 0 :(得分:4)

请改用ModalView。这是弹出式行为的基类,Popup是添加了标题的ModalView。

答案 1 :(得分:2)

您只需要将title属性设置为"",将separator_height属性设置为0

示例:

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