在kivy1.10.0中定制弹出屏幕

2024-09-30 01:29:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我目前正在尝试使用kivy1.10.0在python3.6中创建一个自定义的MessageBox。我想首先使用它作为一个消息框,当用户输入错误的用户名或密码时,错误消息。 每当我使用CalcRoot类的nextScreen函数从CalcPopUp类调用open函数时,都会遇到一个属性错误。在

这是我的密码:

类CalcRoot(BoxLayout):

def __init__(self,**kwargs):
    super(CalcRoot,self).__init__(**kwargs)
    self.calc_popup = CalcPopUp(**kwargs)

def nextScreen(self, next_screen):
    #I have some conditions inside this function which works fine
    CalcPopUp.open(self, "Incorrect Login", True)`

类CalcPopUp(弹出):

^{pr2}$

这是我得到的错误:

AttributeError: 'CalcRoot' object has no attribute 'popup_button'

这是与我的屏幕弹出关联的kivy文件的内容:

<CalcPopUp>:
size_hint: .8, .4
title: "Message"
title_size: root.height *.05
auto_dismiss: False
separator_color: COLOR("#fcfc02") #yellow
popup_button: popup_button
popup_message: popup_message

BoxLayout:
    orientation: 'horizontal'
    padding: root.width * .02, root.height * .02
    spacing: min(root.height, root.width) * .02
    Label:
        id: popup_message
        text: ""
        halign: 'left'
        font_size: root.height / 10
        center_y: .5
        markup: True
    Button:
        id: popup_button
        text: 'Ok'
        size_hint: 1, None
        height: root.height / 20
        on_release: root.dismiss()

Tags: 函数self消息密码messagesize错误button
1条回答
网友
1楼 · 发布于 2024-09-30 01:29:31

我是这样做的:

首先,删除.kv文件中的第7行和第8行。我不确定您的原始帖子中是否有缩进错误,但是现在.kv文件应该是这样的:

<CalcPopUp>:
    size_hint: .8, .4
    title: "Message"
    title_size: root.height *.05
    auto_dismiss: False

    BoxLayout: # this is indented to be inside CalcPopUp
        orientation: 'horizontal'
            ... # etc., no changes other than indentation...

我对.py文件结构做了相当大的更改,请看一下,如果有什么需要解释的,请告诉我:

^{pr2}$

相关问题 更多 >

    热门问题