Python 从Kivy中的另一个类访问函数

Python 从Kivy中的另一个类访问函数,python,python-3.x,kivy,kivy-language,Python,Python 3.x,Kivy,Kivy Language,我试图把一个旋钮,当释放,运行一个功能。为此,我需要在触摸屏上使用并覆盖它。因为我需要返回一个super类来覆盖这个函数,所以我创建了另一个名为AngleKnob(Knob)的类 为了能够使用主类(EngledScreen)中的runexp()函数,我使用了本条目中提到的过程,使用了App.get\u running\u App()。screen: 这是我的密码: #kivy imports from kivy.app import App from kivy.uix.widget import

我试图把一个旋钮,当释放,运行一个功能。为此,我需要在触摸屏上使用
并覆盖它。因为我需要返回一个
super
类来覆盖这个函数,所以我创建了另一个名为
AngleKnob(Knob)
的类

为了能够使用主类(
EngledScreen
)中的
runexp()
函数,我使用了本条目中提到的过程,使用了
App.get\u running\u App()。screen

这是我的密码:

#kivy imports
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.gridlayout import GridLayout
from kivy.uix.slider import Slider
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from kivy.uix.checkbox import CheckBox
from kivy.garden.knob import Knob
from kivy.graphics import Rectangle, Color
from  kivy.uix.popup import Popup

from kivy.properties import ObjectProperty, NumericProperty
import math

from entangledexp import entangledEXP  #importa les funcions que tenen a veure amb l'experiment.

class TablePopup(FloatLayout):
    g_rectangle = ObjectProperty()

    def __init__(self, *args, **kwargs):
        super(TablePopup, self).__init__(*args, **kwargs)

class entangledscreen(BoxLayout):
    n_label=ObjectProperty()  #ara n és una propietat de entangledscreen i farem self. bla bla
    label_s1=ObjectProperty()
    label_s2=ObjectProperty()
    s_label=ObjectProperty()
    table_checkbox=ObjectProperty()
    table_popup=ObjectProperty()
    knoblay=ObjectProperty()
    def __init__(self, *args, **kwargs):
        super(entangledscreen, self).__init__()
        self.experiment = entangledEXP()
        self.table_checkbox.bind(active=self.on_checkbox_Active)#lliga la checkbox amb la funció

    def add_photons(self,a):
        self.experiment.addphotons(n=self.experiment.n+a) #suma 1000 als fotons a llençar
        self.n_label.text=str(self.experiment.n)

    def runexp(self):
        self.experiment.alpha=int(self.label_s1.text)*math.pi/180#convertim a radians i assignem els parametres per poder fer l'experiment
        self.experiment.beta = int(self.label_s2.text)*math.pi/180
        self.experiment.photons=int(self.n_label.text)

        table1 = self.experiment.expqua()
        s=self.experiment.scalc(table1)
        sigma=self.experiment.sigma(table1)
        print(s,"±",sigma)
        rounder=sigma
        factorcounter=0
        while rounder<1:
            rounder=rounder*10
            factorcounter+=1

        sr=round(s,factorcounter)
        sigmar=round(sigma, factorcounter)
        self.s_label.text='[font=Digital-7][color=000000][size=34] S='+str(sr)+'[/font]'+'±'+'[font=Digital-7]'+str(sigmar)+'[/color][/font][/size]'
        return(sr," ± ",sigmar)

    def open_table_popup(self):
        '''opens popup window'''
        popuplayout= TablePopup()# es un float layout q posem com a content al popup

        self.table_popup= Popup(title='Table 1',content=popuplayout,size_hint=(1,1))
        self.table_popup.open()

    def close(self):
        self.table_popup.dismiss()
        self.table_checkbox.active = False  # reseteja la chkbox

    def on_checkbox_Active(self, checkboxInstance, isActive):
        if isActive:
            self.open_table_popup()
    pass
class AngleKnob(Knob):
    def __init__(self, **kwargs):
        self.screen = App.get_running_app().screen
    def on_touch_up(self, touch):
        if self.collide_point(touch.x,touch.y):
            self.screen.runexp()
        return super(AngleKnob,self).on_touch_up(touch)
    pass

class entangledApp(App):

    """"""
    screen = entangledscreen()
    def build(self):

        return entangledscreen

if __name__ == "__main__":
    app = entangledApp()
    app.run()
当我运行程序时,出现一个与复选框相关的错误:

Traceback (most recent call last):
   File "entangled.py", line 92, in <module>
     class entangledApp(App):
   File "entangled.py", line 95, in entangledApp
     screen = entangledscreen()
   File "entangled.py", line 39, in __init__
     self.table_checkbox.bind(active=self.on_checkbox_Active)#lliga la checkbox amb la funció
 AttributeError: 'NoneType' object has no attribute 'bind'
回溯(最近一次呼叫最后一次):
文件“Engulated.py”,第92行,在
类DAPP(应用程序):
文件“Engulated.py”,第95行,在EngulatedApp中
screen=dscreen()
文件“Engulated.py”,第39行,在_init中__
self.table_checkbox.bind(active=self.on_checkbox_active)#lliga la checkbox amb la funció
AttributeError:“非类型”对象没有属性“绑定”
我发现它只在我在
entrangedApp
类中定义
screen=entrangedScreen()
时出现

我完全迷路了,我不知道为什么会这样。。。提前感谢

Traceback (most recent call last):
   File "entangled.py", line 92, in <module>
     class entangledApp(App):
   File "entangled.py", line 95, in entangledApp
     screen = entangledscreen()
   File "entangled.py", line 39, in __init__
     self.table_checkbox.bind(active=self.on_checkbox_Active)#lliga la checkbox amb la funció
 AttributeError: 'NoneType' object has no attribute 'bind'