[英]object has no attributes (kivy)
I am currently working on a mental health app and I have come to a problem in my code.我目前正在开发一个心理健康应用程序,但我的代码遇到了问题。 In one of my classes called 'Controller', I have a slider widget and four buttons that are meant to direct to other pages.
在我的一个名为“控制器”的类中,我有一个 slider 小部件和四个用于指向其他页面的按钮。 However, when I click on one, I am met with this error
但是,当我单击一个时,我遇到了这个错误
File "kivy\weakproxy.pyx", line 32, in kivy.weakproxy.WeakProxy.__getattr__
AttributeError: 'Controller' object has no attribute 'Screen_One'
This is confusing me because from the coding in my class which will now show you:这让我很困惑,因为我的 class 中的编码现在将向您显示:
class Controller(Screen):
def __init__(self):
super(Controller, self).__init__()
def new_thickness(self, *args):
self.lbl.text = str(int(args[1]))
self.lbl.font_size = int(args[1]) * 6 + 10
def screen_one(self)
self.reset()
sm.current = "Screen_One"
At first sight, it looks fine and I have been checking and I can't seem to find the problem with it.乍一看,它看起来很好,我一直在检查,我似乎找不到它的问题。 So I thought it could be the class for my Screen_One which I will now show you:
所以我认为它可能是我的 Screen_One 的 class,现在我将向您展示:
class Screen_One(Screen):
text = ObjectProperty(None)
But as you can see there isn't much to present as it is all manufactured on my kivy or kv file and even that seems to be fine as I will present to you now:但是正如您所看到的,没有太多要展示的东西,因为它都是在我的 kivy 或 kv 文件上制造的,即使这样似乎也很好,因为我现在将向您展示:
This is the button that is meant to move to the page I need to go这是用于移动到我需要的页面的按钮 go
Button:
pos_hint: {"x": 0.0, "y": 11.5}
text: 'Diary'
background_color: 0, 0, 0, 1
on_release:
app.root.current = "Screen_One"
root.manager.transition.direction = "right"
root.Screen_One()
And the code for the page itself:页面本身的代码:
<Screen_One>:
name: 'screen_one'
text: text
FloatLayout
Label:
text: "You can express how you feel below :)"
size_hint: 0.8, 0.2
pos_hint: {"x":0.1, "top":1}
font_size: (root.width**2 + root.height**2) / 14**4
TextInput:
id: text
font_size: (root.width**2 + root.height**2) / 15**4
multiline: False
pos_hint: {"x": 0.5 , "top":0.8}
size_hint: 0.4, 0.12
This projects needed for my grade which is due soon so could someone please help me?我的成绩需要这个项目,很快就要到期了,所以有人可以帮助我吗?
Thank you:)谢谢:)
Change sm.current = Screen_One
to sm.current = "screen_one"
.将
sm.current = Screen_One
更改为sm.current = "screen_one"
。 You need to refer to the name of the screen, not the class name you've give it您需要参考屏幕的名称,而不是您给它的 class 名称
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.