Python 为什么我的kivy标签上没有显示文字?

Python 为什么我的kivy标签上没有显示文字?,python,text,label,kivy,Python,Text,Label,Kivy,据我所知,我的代码是好的,因为IDE没有错误,我在另一个项目中使用了相同的代码,它工作正常。我从一些帖子中读到,可能对象没有.text()方法,这会给我一个错误,但我没有错误。另一个帖子可能是因为没有将表设置为对象。据我所知,我正确地引用了所有内容 它是否与数据类型有关?再次感谢您的一些见解 main.py from kivy.app import App from kivy.uix.widget import Widget from kivy.uix.button import Button

据我所知,我的代码是好的,因为IDE没有错误,我在另一个项目中使用了相同的代码,它工作正常。我从一些帖子中读到,可能对象没有.text()方法,这会给我一个错误,但我没有错误。另一个帖子可能是因为没有将表设置为对象。据我所知,我正确地引用了所有内容

它是否与数据类型有关?再次感谢您的一些见解

main.py

from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.button import Button
from kivy.lang.builder import Builder
from kivy.properties import ObjectProperty, StringProperty
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.graphics import Rectangle, Color
import socket

class Screen_Manager(ScreenManager):
    screen_1 = ObjectProperty()

class Screen_1(Screen):
    main_display = ObjectProperty()

    def __init__(self, **kwargs):
        super(Screen_1, self).__init__(**kwargs)

    def get_host(self):
        self.s = socket.gethostbyname(socket.gethostname())
        return self.s


class MainApp(App):

    def build(self):
        self.title = "Number Display App"
        self.sm = Screen_Manager()
        return self.sm

if __name__=="__main__":
    MainApp().run()
梅因·肯塔基

<Screen_Manager>:
    Screen_1:

<Screen_1>:
    id: screen_1
    name: "first"

    main_display: display_1

    Label:
        id: display_1
        text: root.get_host()
        font_size: "30sp"
:
屏幕1:
:
id:屏幕1
姓名:“第一”
主显示器:显示器1
标签:
id:显示_1
text:root.get_host()
字体大小:“30sp”

看起来您没有将标签的文本设置为除
之外的任何内容。

嗨@increment,通过访问更多内容使其正常工作。我非常感激。现在更新代码。