【问题标题】:How to remove popup title in kivy如何在kivy中删除弹出标题
【发布时间】:2018-06-11 13:27:36
【问题描述】:

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

从这里

到这里

提前致谢!

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

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

【问题讨论】:

  • 显示你的代码。

标签: python kivy


【解决方案1】:

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

【讨论】:

  • 我猜这个可以稍微提高运行时间,所以我一定会添加它。谢谢!
【解决方案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()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-05
    • 2018-06-13
    • 1970-01-01
    • 1970-01-01
    • 2016-01-10
    • 1970-01-01
    • 1970-01-01
    • 2021-12-27
    相关资源
    最近更新 更多