Python Kivy不显示在Raspberry Pi 3上运行的窗口

Python Kivy不显示在Raspberry Pi 3上运行的窗口,python,user-interface,raspberry-pi,kivy,Python,User Interface,Raspberry Pi,Kivy,我正在尝试在树莓圆周率上运行我的Kivy应用程序 用例是为RFID控制的咖啡机显示一个界面 扫描部分工作正常,所有的东西都显示界面工作正常,因为在切换到Kivy之前,我用TKinter对它进行了测试 这是我的密码: import RPi.GPIO as GPIO #Access to the Raspberry Pi GPIO Pins import serial #PySerial for the serial connection to the RFID

我正在尝试在树莓圆周率上运行我的Kivy应用程序
用例是为RFID控制的咖啡机显示一个界面
扫描部分工作正常,所有的东西都显示界面工作正常,因为在切换到Kivy之前,我用TKinter对它进行了测试

这是我的密码:

import RPi.GPIO as GPIO     #Access to the Raspberry Pi GPIO Pins
import serial               #PySerial for the serial connection to the RFID reader
import time                 #Required for sleep function
import datetime             #Required for timestamp
import MySQLdb as SQL       #Connection to MySQL Database
import threading            #Threading for RFID detection

from subprocess import call #Um die Datei in einem neuen Thread aufzurufen

import kivy                #GUI
kivy.require('1.10.0')

from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.uix.boxlayout import BoxLayout
from kivy.clock import Clock
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.lang import Builder


#GPIO Setup
GPIO.setmode(GPIO.BCM)

GPIO.setup(18, GPIO.OUT)
GPIO.setup(21, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

GPIO.output(18, GPIO.HIGH)

#MySQL DB Connection
db = SQL.connect("localhost", "root", "raspberry", "Coffee")
curs = db.cursor()

#Select NTUser by the read ID from the MySQL Database
def getID(readID):
    try:
        curs.execute("SELECT NTUSER FROM usrlist WHERE id=%s", readID)
        usr = curs.fetchone()
        return usr[0]
    except:
        print("User not registered")


def put_into_db():
    #Input data into the Database
    print('done')



def espresso():
    print('Espresso')

def coffee():
    print('Coffee')



def scanner_thread():
    call(["python", "/RFID_Coffeemachine/RFID_Scanner.py", "&"])

#Thread for RFID reading
thread = threading.Thread(target=scanner_thread)
thread.start()

class Coffee(Screen):
    def __init__ (self,**kwargs):
    #GUI
        layout_coffee = BoxLayout(orientation="vertical")
        header_coffee = BoxLayout(orientation="horizontal")
        body_coffee = BoxLayout(orientation="horizontal")
        footer_coffee = BoxLayout(orientation="horizontal")



        self.greeting = Label(
            text='Welcome to the config screen',
            size_hint=(.5, .25))                        #Greeting Label
        def get_login(self):                                  #Function to update the greeting label -> Later integration with the user DB
            login_file = open('/home/pi/login.txt', "r")
            current_login = login_file.readline()
            login_file.close()
            if current_login == ' ':
                self.greeting.text='Please Scan RFID Token'
            else:
                self.greeting.text = current_login

        body_coffee.add_widget(self.greeting)                   #Adding the Label to the Layout
        Clock.schedule_interval(get_login, 1)              #Updating the greeting text every second

        layout_coffee.add_widget(header_coffee)
        layout_coffee.add_widget(body_coffee)
        layout_coffee.add_widget(footer_coffee)

class Config(Screen):
    def __init__ (self,**kwargs):
    #GUI
        layout_config = BoxLayout(orientation="vertical")
        header_config = BoxLayout(orientation="horizontal")
        body_config = BoxLayout(orientation="horizontal")
        footer_config = BoxLayout(orientation="horizontal")

        greeting = Label(
            text='Welcome to the config screen',
            size_hint=(.5, .25))                           #Greeting Label
        body_config.add_widget(greeting)                   #Adding the Label to the Layout

        layout_config.add_widget(header_config)
        layout_config.add_widget(body_config)
        layout_config.add_widget(footer_config)

class GUIApp(App):
    def build(self):

        screens = ScreenManager()

        coffee = Coffee(name="coffee")
        config = Config(name="config")

        screens.add_widget(coffee)
        screens.add_widget(config)

        return screens  



if __name__ == "__main__":
    GUIApp().run()
#thread.stop()
#db.close()
#ser.close()
我很确定我做了
导入
“\uuuuuu main\uuuuuuu”
对,这是类似问题的帖子中的问题。
我还非常确定Kivy的安装在Pi上运行正常,因为演示应用程序运行良好。

所以我似乎缺少了一些东西:

要使屏幕正常工作,我需要添加:
def\uuu init\uuuu(self,**kwargs):
在每个屏幕类之后,将所有布局和小部件放在其中

此外,我忘了将布局添加到屏幕:

self.add\u widget(layout\u coffee)
\uuuu init\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu?如何连接X-server?是的,覆盆子有一个监视器(hdmi),Kivy样本在上面运行良好@dsgdfg
如果uuuu name_uuuuu==“uuuuu main_uuuuuu”:GUIApp().run();导入时间;而对:时间。睡眠(100)