繁体   English   中英

Kivy AttributeError: 'NoneType' object 没有属性 'current'

[英]Kivy AttributeError: 'NoneType' object has no attribute 'current'

我是 Kivy 的新手,非常感谢一些帮助。 我正在尝试使“管理居民”按钮切换屏幕,但出现错误:

self.manager.current = 'manageResidents'
AttributeError: 'NoneType' object has no attribute 'current''

这是我的代码:

import sqlite3
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.uix.dropdown import DropDown
from kivy.base import runTouchApp
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.textinput import TextInput
from kivy.properties import ObjectProperty
        
class mainMenu(Screen):
    def __init__(self, **kwargs):
        super(mainMenu, self).__init__(**kwargs)
        # Selects the first name and last name of all residents and sorts by ascending order
        db = sqlite3.connect("mainDatabase.db")    
        cursor = db.cursor()
        dropDownValues = cursor.execute("SELECT firstName, lastName FROM residents ORDER BY firstName ASC").fetchall()
        db.close()
        mainDropdown = DropDown()#Assigns the variable mainDropdown to be a dropdown menu

这是应该改变屏幕的按钮

btn = Button(text="Manage Residents", size_hint_y=None, height=44)#Creates a button at the top of the dropdown menu that switches to manage residents screen
btn.bind(on_release=lambda btn: mainDropdown.select(btn.text))
btn.bind(on_release=self.changer)

Rest 代码:

        mainDropdown.add_widget(btn)
        mainButton = Button(text='Residents', size_hint=(0.25, 0.1))#Sets the name of the dropdown button, sizes it and makes it change its text to what the user has clicked on
        mainButton.bind(on_release=mainDropdown.open)
        runTouchApp(mainButton)
    def changer(self,*args):
        self.manager.current = 'manageResidents'

class manageResidents(Screen):
    def __init__(self, **kwargs):
        super(manageResidents, self).__init__(**kwargs)
        my_label1 = Label(text="You are now on manage residents screen", font_size='24dp')

class MyApp(App):
    def build(self):
        my_screenmanager = ScreenManager()
        screen1 = mainMenu(name='Main Menu')
        screen2 = manageResidents(name='Manage Residents')
        my_screenmanager.add_widget(screen1)
        my_screenmanager.add_widget(screen2)
        return my_screenmanager

if __name__ == "__main__":
    MyApp().run()here

问题

您的应用程序中有两个问题。

  1. 在您的应用程序中,它正在运行runTouchApp(mainButton) 因此,没有属性“当前”
  2. 没有“manageResidents”的网

解决方案

  1. runTouchApp(mainButton)替换为self.add_widget(mainButton)
  2. “manageResidents”替换为“ManageResidents”

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM