KivyMD-在DialogBox中使用时无法更新TextField的文本

如何解决KivyMD-在DialogBox中使用时无法更新TextField的文本

我已经使用 KivyMD 开发了一个屏幕,该屏幕显示特定项目的参数值(在对话框中)(我将其列为 OnelinelistItem )。我还想为用户提供从对话框更改参数值的条件。但显然我无法从对话框更新参数设置。该对话框包含文本字段。谁能帮助我通过遍历代码来找出问题,并让我知道我在哪里做错了? TIA ! :)

testingsetpointpage.py

'''

from kivy.config import Config
Config.set('kivy','keyboard_mode','systemanddock')
from kivy.uix.boxlayout import BoxLayout
from kivymd.app import MDApp
from kivy.lang.builder import Builder
from kivy.uix.screenmanager import Screen
from kivymd.uix.dialog import MDDialog
from kivy.properties import ObjectProperty
from kivy.core.window import Window
from kivymd.uix.button import MDFlatButton
from kivy.properties import StringProperty
Window.size = (1024,600)

此处显示了生成器:

KV = """
#:kivy 1.11.0
#:import MDDropdownMenu kivymd.uix.menu.MDDropdownMenu
#:import MDRaisedButton kivymd.uix.button.MDRaisedButton
ScreenManager:
    MainScreen:
<MainScreen>:   
    name: 'mainscreen'
    NavigationLayout:
        ScreenManager:
            Screen:                
                name: 'homemain'
                BoxLayout:
                    orientation:"vertical"
                    halign:"center" 

                    #DOWN TAB          
                    MDBottomNavigation:                        
                        MDBottomNavigationItem:
                            name: 'setpoint'
                            text: 'Setpoints'
                            icon: 'network'
                              
                            BoxLayout:
                                orientation: "vertical"
                                
                                MDToolbar:
                                    title: 'Setpoints'
                                    pos_hint: {'center_x':0.5,'center_y':0.95}   
                                    right_action_items: [["wifi",lambda x: app.navigation_draw()]]
                                    left_action_items: [["menu",lambda x: nav_drawer.toggle_nav_drawer()]]
                                    elevation: 10
                                
                                BoxLayout:
                                    orientation:"vertical"
                                    padding: 5
                                    spacing: 5
                                    MDLabel:
                                        text: "     Functions: "
                                        halign:"left"
                                        theme_text_color: "Custom"
                                        text_color: 0,1,1
                                        size_hint_y: 0.15
                                        canvas.before:
                                            Color:
                                                rgba: (211/255.0,211/255.0,1)
                                            Rectangle:
                                                size: self.size
                                                pos: self.pos
                                    SetpointContent:
                                    
#MAKE THE PARAMETER LIST                                            
<SetpointContent>: 
 
    BoxLayout:
        orientation: "vertical"
        padding: 5
        spacing: 5

        ScrollView:
            MDList:
                OneLineListItem:
                    text: "51P: Phase Time Overcurrent"
                    on_press: root.show_51Pdata()
                
    
<Content51P>
    alarmpick51p: alp51p
    alarmdelay51p: ald51p
    trippick51p: trp51p
    invcurve51p: inp51p
    orientation: "vertical"
    size_hint_y: None
    height: "200dp"
    GridLayout:
        rows: 4
        cols: 2
        spacing: 10
        
        MDLabel:
            text: "Alarm Pickup: "
            halign: "center"
            theme_text_color: "Custom"
            text_color: 0,1
            size_hint_y: 0.15
            size_hint_x: 0.4
            width:100
        MDTextFieldRect:
            id: alp51p
            text: root.text1
            multiline: False
        MDLabel:
            text: "Alarm Delay: "
            halign: "center"
            theme_text_color: "Custom"
            text_color: 0,1
            size_hint_y: 0.15
            size_hint_x: 0.4
            width:100
        MDTextFieldRect:
            id: ald51p
            text: str(app.Aldelay51P)
            multiline: False
        MDLabel:
            text: "Trip Pickup:  "
            halign: "center"
            theme_text_color: "Custom"
            text_color: 0,1
            size_hint_y: 0.15
            size_hint_x: 0.4
            width:100
        MDTextFieldRect:
            id: trp51p
            text: str(app.Trpick51P)
            multiline: False
        MDLabel:
            text: "Inverse Curve:  "
            halign: "center"
            theme_text_color: "Custom"
            text_color: 0,1
            size_hint_y: 0.15
            size_hint_x: 0.4
            width:100
        MDTextFieldRect:
            id: inp51p
            text: str(app.InverseCurve)
            multiline: False
                            #####                                                                         
"""

和类在这里定义:

class Content51P(BoxLayout):
    app=MDApp.get_running_app()
    text1 = StringProperty("1")
    alarmpick51p = ObjectProperty()
    alarmdelay51p = ObjectProperty()
    trippick51p = ObjectProperty()
    invcurve51p = ObjectProperty()



class MainScreen(Screen):
    class SetpointContent(Screen):

        def show_51Pdata(self):
            self.dialog = MDDialog(title="51P Parameters:",type="custom",content_cls=Content51P(),buttons=[MDFlatButton(text='Close',on_release=self.close_dialog),MDFlatButton(text='Update',on_release=self.update51P)]
                                   )
            self.dialog.auto_dismiss = False
            self.dialog.open()

        def update51P(self,obj):
            duc = Content51P()
            app = MDApp.get_running_app()
            duc.text1 = duc.ids.alp51p.text
            print(duc.text1)
            app.Alpick51P = float(duc.text1)
            print(app.Alpick51P)

        def close_dialog(self,obj):
            self.dialog.auto_dismiss = True
            self.dialog.dismiss()


class MainApp(MDApp):
    Alpick51P = ObjectProperty("5")
    Aldelay51P = ObjectProperty("5")
    Trpick51P = ObjectProperty("5")
    InverseCurve = ObjectProperty("Very Inverse")

    def build(self):
        self.theme_cls.primary_palette = "Blue"
        screen = Builder.load_string(KV)
        return screen

    def navigation_draw(self):
        print("Navigation")

    def on_start(self):
        pass


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

''' The outlook looks something like this. I want to update the four parameters as the user clicks on the Update button and be able to view the value,the next time I open the DialogBx.

解决方法

在kv规则中,<Content51P>的{​​{1}}文本输入下添加:

MDTextFieldRect

on_text: app.Alpick51P = self.text on_text: app.Aldelay51P = self.text on_text: app.Trpick51P = self.text on_text: app.InverseCurve = self.text 方法应转到相应的on_text

现在更新MDTextFieldRect函数应该如下:

update51P()

这现在将打印来自textinput字段的更新的输入。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-