更新Kivy Popup中显示的进度条 - python

您如何更新Kivy中显示的进度条。在以下示例中,我得到AttributeError: 'super' object has no attribute '__getattr__'。问题在以下行中

self.ids.progress.value = value

我可以理解为什么progressBar小部件位于<LoadingPopup>中而不是<MainScreen>中,但是尝试了几种不同的操作后,我无法从progressBar引用<LoadingPopup>中的do_update method小部件。

提前致谢

import threading
from functools import partial

from kivy.lang import Builder
from kivy.uix.floatlayout import FloatLayout
from kivy.properties import StringProperty
from kivy.uix.spinner import Spinner
from kivy.app import App
from kivy.clock import Clock
from kivy.uix.popup import Popup



Builder.load_string('''

<LoadingPopup>:
    title: "Popup"
    size_hint: None, None
    size: 400, 400
    auto_dismiss: False

    BoxLayout:
        orientation: "vertical"
        ProgressBar:
            id: progress
            size_hint: (1.0, 0.06)

<MainScreen>:
    BoxLayout:
        orientation: 'vertical'

        Spinner:
            id: first
            text: ' First Number'
            values: ['1','2','3','4','5','6','7','8','9']

        Spinner:
            id: second
            text: ' Second Number'
            values: ['1','2','3','4','5','6','7','8','9']

        Label:
            id: result
            text: ' Result'
            color: 0,0,0,1
        Button:
            id: res
            on_press: root.doit_in_thread(first.text,second.text)
            text: 'Multiply'


''')

class LoadingPopup(Popup):

    def __init__(self, obj, **kwargs):
        super(LoadingPopup, self).__init__(**kwargs)


class MainScreen(FloatLayout):
    changet = StringProperty()
    def __init__(self, **kwargs):
        super(MainScreen, self).__init__(**kwargs)

    def doit_in_thread(self, fir, sec):
        popup = LoadingPopup(self)
        popup.open()
        threading.Thread(target=partial(self.onMul, fir, sec, popup)).start()

    def do_update(self, value, text, *args):
        self.ids.progress.value = value
        self.ids.result.text = text

    def onMul(self,fir,sec, popup):
        a = (int(fir)*int(sec))
        print(a)
        b = 0
        old_value = 0
        endRange = 1000000
        for i in range(endRange):
            progress = int(((i+1)*100)/endRange)
            if progress != old_value and progress % 5 == 0:
                text = str(b*(int(fir)*int(sec)))
                Clock.schedule_once(partial(self.do_update, progress, text))
                old_value = progress
            b+=1

        popup.dismiss()

class TestApp(App):
    def build(self):
        return MainScreen()

if __name__ == "__main__":
    TestApp().run()

参考方案

一种方法是保留对弹出窗口的引用,以便稍后进行处理:

def __init__(self, **kwargs):
    super(MainScreen, self).__init__(**kwargs)
    self.popup = LoadingPopup(self)

def doit_in_thread(self, fir, sec):
    self.popup.open()
    threading.Thread(target=partial(self.onMul, fir, sec, self.popup)).start()

def do_update(self, value, text, *args):
    self.popup.ids.progress.value = value
    self.ids.result.text = text

在返回'Response'(Python)中传递多个参数 - python

我在Angular工作,正在使用Http请求和响应。是否可以在“响应”中发送多个参数。角度文件:this.http.get("api/agent/applicationaware").subscribe((data:any)... python文件:def get(request): ... return Response(seriali…

Python exchangelib在子文件夹中读取邮件 - python

我想从Outlook邮箱的子文件夹中读取邮件。Inbox ├──myfolder 我可以使用account.inbox.all()阅读收件箱,但我想阅读myfolder中的邮件我尝试了此页面folder部分中的内容,但无法正确完成https://pypi.python.org/pypi/exchangelib/ 参考方案 您需要首先掌握Folder的myfo…

R'relaimpo'软件包的Python端口 - python

我需要计算Lindeman-Merenda-Gold(LMG)分数,以进行回归分析。我发现R语言的relaimpo包下有该文件。不幸的是,我对R没有任何经验。我检查了互联网,但找不到。这个程序包有python端口吗?如果不存在,是否可以通过python使用该包? python参考方案 最近,我遇到了pingouin库。

Python ThreadPoolExecutor抑制异常 - python

from concurrent.futures import ThreadPoolExecutor, wait, ALL_COMPLETED def div_zero(x): print('In div_zero') return x / 0 with ThreadPoolExecutor(max_workers=4) as execut…

如何用'-'解析字符串到节点js本地脚本? - python

我正在使用本地节点js脚本来处理字符串。我陷入了将'-'字符串解析为本地节点js脚本的问题。render.js:#! /usr/bin/env -S node -r esm let argv = require('yargs') .usage('$0 [string]') .argv; console.log(argv…