You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

KivyMD中对话框尺寸调整异常问题求助

KivyMD对话框显示异常及输入格式问题

我尝试在KivyMD的对话框中容纳MDTextField与自定义键盘,期望对话框能完整显示所有内容,但当前遇到两个问题:

  • 对话框背景后出现黑色阴影,显示尺寸设置存在问题;
  • 点击按键时,正确格式会短暂弹出后消失。

对话框显示效果对比:
对话框显示异常对比图

使用的Python代码

def open_keyboard(self):
    if self.dialog:
        self.dialog.dismiss()

    keyboard_content = MDBoxLayout(orientation="vertical", adaptive_height = True)
    keyboard_content.add_widget(KeyboardContent())

    self.dialog = MDDialog(
        type="custom",
        content_cls=keyboard_content,
        size_hint=(0.8, .9) 
    )
    self.dialog.open()

对应的Kivy代码

<KeyboardContent>:
BoxLayout:
    orientation: "vertical"

    MDTextField:
        id: text_input
        hint_text: "Type here"
        required: True
        max_text_length: 50

    GridLayout:
        cols: 6
        spacing: "10dp"

        MDRectangleFlatButton:
            text: "A"
            on_release:
                root.add_text("A")
                app.speak_text("a")

        MDRectangleFlatButton:
            text: "B"
            on_release:
                root.add_text("B")
                app.speak_text(self.text)

内容的提问来源于stack exchange,提问作者She-Codes

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 04:21:12