Change:
def PressMe(self):
TestApp().PressMe2()
to:
def PressMe(self):
self.PressMe2()
Your code is creating a new instance of the App. You want to use the self object to select the method in the class.
From: Laurentiu Ion
Sent: Tuesday, September 27, 2022 12:40 PM
To: Kivy users support
Subject: [kivy-users] kivymd AttributeError: 'NoneType' object has noattribute 'ids'
Hello,
I have a simple program that calls a function which updates a text Label. If I call the function by pressing a button it works. However, if I call the function from another function in py file I receive the error in the subject. Could you please tell me how can I call the function from another function so I don't receive the error?
kv file
-----------------
MDBoxLayout:
orientation: 'vertical'
MDScreen:
MDSmartTile:
box_color: 1, 1, 1, .2
pos_hint: {"center_x": .5, "center_y": .5}
size: self.size
MDLabel:
id: p1Label
text:'button is not pressed'
bold: True
font_size: 30
halign: 'center'
valign: 'center'
size_hint_y: None
height: self.texture_size[1]
pos_hint: {'center_x': 0.5, 'center_y': 0.95}
outline_color: (0,0,0)
outline_width: 4
MDRaisedButton:
id: creditButton
text: 'Press me!'
pos_hint: {"center_x": 0.2, "center_y": 0.05}
size_hint: 0.1, 0.05
on_press: app.PressMe()
font_style: 'Button'
py file that works
-----------------------------------------
from kivy.lang import Builder
from kivymd.app import MDApp
class TestApp(MDApp):
def build(self):
self.title = 'TestApp'
self.theme_cls.theme_style = "Dark"
self.theme_cls.primary_palette = "Indigo"
#self.theme_cls.accent_palette = "Red"
return Builder.load_file('test.kv')
def PressMe(self):
self.root.ids.p1Label.text = 'You pressed the button'
TestApp().run()
py file that does not work
-----------------------------------------------
from kivy.lang import Builder
from kivymd.app import MDApp
class TestApp(MDApp):
def build(self):
self.title = 'TestApp'
self.theme_cls.theme_style = "Dark"
self.theme_cls.primary_palette = "Indigo"
#self.theme_cls.accent_palette = "Red"
return Builder.load_file('test.kv')
def PressMe(self):
TestApp().PressMe2()
def PressMe2(self):
self.root.ids.p1Label.text = 'You pressed the button'
TestApp().run()
error
---------------
File "D:\code\python3Workspace\test.py", line 17, in PressMe2 self.root.ids.p1Label.text = 'You pressed the button' AttributeError: 'NoneType' object has no attribute 'ids'
Thanks in advance
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/520eef37-9c5b-43db-b97e-915c59b042fbn%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/63335961.ca0a0220.d1e3a.ea43SMTPIN_ADDED_MISSING%40gmr-mx.google.com.