第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

初始化時(shí)無(wú)法訪問(wèn)類錯(cuò)誤代碼中的實(shí)例

初始化時(shí)無(wú)法訪問(wèn)類錯(cuò)誤代碼中的實(shí)例

動(dòng)漫人物 2022-07-12 18:17:06
每次我嘗試初始化一個(gè) kivy 屏幕時(shí),即使我已經(jīng)研究過(guò),我總是會(huì)收到一個(gè)錯(cuò)誤,這表明我以正確的方式進(jìn)行操作。我想從 my 訪問(wèn)實(shí)例,我 ProjectListScreen class將實(shí)例初始化為 None 但將屏幕初始化為 ApplyPage 不起作用,我嘗試使用 Factory 將類實(shí)例化到 myApplyPage class 中,但它仍然沒(méi)有返回實(shí)例的值。下面是我的代碼,之后是我嘗試初始化屏幕類時(shí)的回溯。我將不勝感激任何幫助。請(qǐng)我整天都在為此苦苦掙扎。class ProjectListScreen(Screen):    project_list = ObjectProperty(None)    def __init__(self, **kwargs):        super(ProjectListScreen, self).__init__(**kwargs)        self.thelocalId = None        self.placementtext = None    def on_pre_enter(self, *args):        placements = database.child("placements").get()        placementslist = placements.val()        placementslist.items()        for key, value in placementslist.items():            self.key = key            key_list = []            key_list.append(key)            for key in key_list:                name = database.child("placements").child(str(key)).child("placement name").get()                description = database.child("placements").child(str(key)).child("placement description").get()                location = database.child("placements").child(str(key)).child("placement location").get()                date = database.child("placements").child(str(key)).child("placement date").get()                price = database.child("placements").child(str(key)).child("placement price").get()                thelocalId = database.child("placements").child(str(key)).child("localId").get()                self.thelocalId = thelocalId.val()                self.project_list.adapter.data.extend([ "\n" + "\n" + str(name.val()) + '\n' + str(description.val()) + "\n" + str(location.val()) + '\n' + str(date.val()) + '\n' + '\n' + str(price.val())])    def gettext(self):        self.placementtext = self.project_list.adapter.selection[0].textclass ApplyPage(Screen):    projectlistscreen = ObjectProperty(None)
查看完整描述

2 回答

?
倚天杖

TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超3個(gè)贊

我會(huì)從 .kv 文件中刪除那個(gè)東西


WindowManager:

    id: window manager

    ApplyPage:

        id: applyingpage

        name: "applyingpage"

    ProjectListScreen:

        id: project_list_screen

        name: "project_list_screen"

并從 Python 中刪除


wm = WindowManager()

wm.add_widget(ApplyPage(projectlistscreen=projectlistscreen))


sm = Builder.load_file("kivy.kv")

并從 ApplyPage 類中刪除它


def nopressed(self, instance):

        sm.current = "placements"

你只需要這樣:


class WindowManager(ScreenManager):

    def __init__(self, **kwargs):

        super(WindowManager, self).__init__(**kwargs)


class MyApp(App):

    ...


    def build(self):

        self.refresh_token_file = self.user_data_dir + self.refresh_token_file

        self.thefirebase = MyFireBase()


        # I think you will need these objects later, so better to do it accessable for the whole class

        self.sm = WindowManager()

        self.pls = ProjectListScreen()

        self.applypage = ApplyPage(self.pls)


        # then add that screens to screen manager (it's even more simple than to do it in .kv)

        self.sm.add_widget(self.pls)

        self.sm.add_widget(self.applypage)

        return self.sm


    # if you need a transition to another screen, you can create method here

    def toapplypage(self):

        self.sm.transition.direction = 'left'

        self.sm.current = "applyingpage"

您可以使用方法來(lái)更改其他類中的屏幕,但您需要將您在 build 方法中創(chuàng)建的對(duì)象發(fā)送到那里。所以調(diào)用這些方法就像:


# it's only an example!

self.applypage.nopressed(self.sm)

并且不要忘記在 .kv 文件中寫(xiě)入 ProjectListScreen 類的名稱。


查看完整回答
反對(duì) 回復(fù) 2022-07-12
?
慕后森

TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超5個(gè)贊

__init__()您的類的方法ApplyPage需要位置參數(shù)projectlistscreen。kv加載文件并ApplyPage:遇到 時(shí),將調(diào)用該方法__init__()而不需要所需的projectlistscreen參數(shù)。我建議修改該__init__()方法以使projectlistscreenakwarg參數(shù)為:


def __init__(self, **kwargs):

    self.projectlistscreen = kwargs.pop('projectlistscreen', None)

    super(ApplyPage, self).__init__(**kwargs)

    self.yes = Button(text="Yes", font_size = 20, font_name= "fonts/Qanelas-Heavy.otf", background_color = (0.082, 0.549, 0.984, 1.0), background_normal= '', pos_hint = {"x":0.1,"y":0.05}, size_hint= [0.2, 0.1])

    self.add_widget(self.yes)

    self.no = Button(text="No", font_size= 20, font_name= "fonts/Qanelas-Heavy.otf", background_color = (0.082, 0.549, 0.984, 1.0), background_normal= '', pos_hint = {"x":0.7, "y":0.05}, size_hint= [0.2, 0.1])

    self.no.bind(on_pressed=self.nopressed)

    self.add_widget(self.no)

另外,我從以前的問(wèn)題中識(shí)別出您的代碼,并且您再次犯了我在之前的帖子中指出的相同錯(cuò)誤。你的代碼:


projectlistscreen = ProjectListScreen()

wm = WindowManager()

wm.add_widget(ApplyPage(projectlistscreen=projectlistscreen))

正在創(chuàng)建 a ProjectListScreen、 aWindowManager和 an ApplyPage。這些都沒(méi)有實(shí)際使用。


編碼:


sm = Builder.load_file("kivy.kv")

構(gòu)建與Widgets上面相同,但這些實(shí)際上是使用的,因?yàn)閟m是由您的build()方法返回的。


查看完整回答
反對(duì) 回復(fù) 2022-07-12
  • 2 回答
  • 0 關(guān)注
  • 111 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)