Python Forum
'NoneType' object has no attribute error, when using Kivy Screens
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
'NoneType' object has no attribute error, when using Kivy Screens
#1
I'm working on a multi-screen Kivy app. This is a simplified version, but the basic functionality is that a user should be able to drag files to three labels on the main screen.

I declare self.drops=[] in the App class, and in the label ("DropFile") class I have: 

        app = App.get_running_app()
        app.drops.append(self.on_dropfile)

I was able to get the functionality to work without screens, but when I tried adding a screen manager, I started getting this error: 'NoneType' object has no attribute 'drops'.

Any ideas what's going wrong with "drops"? I've added comments to the code with the "PROBLEM AREAS". If you comment out drops, the app will open (albeit without drag/drop functionality).

Any help would be greatly appreciated!


from kivy.app import App from kivy.uix.button import Button from kivy.core.window import Window from kivy.uix.boxlayout import BoxLayout from kivy.uix.label import Label from kivy.uix.listview import ListView from kivy.uix.gridlayout import GridLayout from kivy.properties import ObjectProperty from kivy.uix.screenmanager import ScreenManager, Screen from kivy.lang import Builder from kivy.properties import ListProperty Builder.load_string(""" <DropFile>: <RunButton>: color: .5,.6,.2,.7 <MenuScreen>:     BoxLayout:         orientation: 'vertical'         DropFile:             text: "Drag file1 here."         DropFile:             text: "Drag file2 here."         DropFile:             text: "Drag file3 here."         RunButton:             text: "Run"             on_press: root.manager.current = "settings"                       <SettingsScreen>:     BoxLayout:         Button:             text: 'My settings button'         Button:             text: 'Back to menu'             on_press: root.manager.current = 'menu' """) # Declare both screens class MenuScreen(Screen):     pass class Box(BoxLayout):     pass class RunButton(Button):     pass class Helper:     pass class DropFile(Label):     def __init__(self, **kwargs):         super(DropFile, self).__init__(**kwargs)         Window.bind(mouse_pos=lambda w, p: setattr(Helper, 'mpos', p)) #PROBLEM AREA 1: Something is malfunctioning with "drops" here         app = App.get_running_app()         app.drops.append(self.on_dropfile)     def on_dropfile(self, widget, filename):         # a function catching a dropped file         # if it's dropped in the widget's area         if self.collide_point(*Window.mouse_pos):             self.text= filename.decode('utf-8')             print(self.text) class SettingsScreen(Screen):     pass # Create the screen manager sm = ScreenManager() sm.add_widget(MenuScreen(name='menu')) sm.add_widget(SettingsScreen(name='settings')) class TestApp(App):          def build(self): #PROBLEM AREA 2: Something is malfunctioning with "drops" here.          self.drops=[]         Window.bind(on_dropfile=self.handledrops)         return sm     def handledrops(self, *args):                  for i in self.drops:             i(*args) if __name__ == '__main__':     TestApp().run()
Reply
#2
on_dropfile does not return anything so by default it returns None.
Reply
#3
(Feb-04-2017, 10:11 PM)Yoriz Wrote: on_dropfile does not return anything so by default it returns None.


https://github.com/kivy/kivy/blob/master...ropfile.py

Thanks. One thing I'm confused about is, the functions seem to work in this code above, but when I modify things a bit (adding screens, but leaving the core drop functions intact) it stops working.
Reply
#4
I spoke too soon. I needed to set up the Screen Manager within the build method.

Thanks for your help!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  type object 'man' has no attribute 'centerX' Tempo 7 2,265 Mar-07-2025, 03:47 AM
Last Post: deanhystad
  error in class: TypeError: 'str' object is not callable akbarza 2 2,855 Dec-30-2023, 04:35 PM
Last Post: deanhystad
Bug TypeError: 'NoneType' object is not subscriptable TheLummen 4 5,075 Nov-27-2023, 11:34 AM
Last Post: TheLummen
  Error: audioio has no attribute 'AudioOut' netwrok 3 2,511 Oct-22-2023, 05:53 PM
Last Post: netwrok
  TypeError: 'NoneType' object is not callable akbarza 4 19,710 Aug-24-2023, 05:14 PM
Last Post: snippsat
  AttributeError: '_tkinter.tkapp' object has no attribute 'username' Konstantin23 4 8,551 Aug-04-2023, 12:41 PM
Last Post: Konstantin23
  Need help with 'str' object is not callable error. Fare 4 3,260 Jul-23-2023, 02:25 PM
Last Post: Fare
  Python: Regex is not good for re.search (AttributeError: 'NoneType' object has no att Melcu54 9 5,129 Jun-28-2023, 11:13 AM
Last Post: Melcu54
  Python: AttributeError: 'PageObject' object has no attribute 'extract_images' Melcu54 2 8,827 Jun-18-2023, 07:47 PM
Last Post: Melcu54
  Error when running kivy on python janeik 8 9,025 Jun-16-2023, 10:58 PM
Last Post: janeik

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.