홈>
라즈베리 파이에서 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()
내가
imports
를했다고 확신한다
그리고
"__main__"
비슷한 문제가있는 게시물의 문제였습니다.
또한 데모 응용 프로그램이 제대로 실행되므로 Kivy 설치가 Pi에서 제대로 작동했는지 확신합니다.
- 답변 # 1
관련 자료
- Raspberry Pi에서 puckel/docker-airflow 이미지 실행
- 플레이어가 [C ++/SFML]의 창에 표시되지 않습니다
- Raspberry Pi Zero W에서 도커 실행
- c# - Win10 IoT를 실행하는 Raspberry Pi는 Wifi와 Bluetooth 통신을 동시에 사용할 수 있습니까?
- sql - 윈도우 함수로 누계
- Powershell에서 "start powershell"을 실행할 때 창 제목을 설정 하시겠습니까?
- android - "팝업"창에 하나의 텍스트보기 만 표시
- VS 코드에서 Python 코드가 제대로 실행되지 않거나 오류가 표시되지 않음
- python - 라즈베리 파이 카메라 - 미리보기 창에 pil 이미지를 어떻게 그리나요?
- selenium - 새 크롬 창을 열기 위해 while 루프 실행
- assembly - emu8086에서 출력을 표시하지 않고 코드가 실행 중
- java - 변경 사항을 표시하지 않는 스윙 응용 프로그램 창
관련 질문
- python : 내 파이썬 GUI 접근 방식에서 프레임 변경 기능을 어떻게 호출할 수 있습니까?
- python : Twitter API가 401(승인되지 않음)을 반환했습니다. 사용자를 인증할 수 없습니다.
- python : ModuleNotFoundError: 'kivymd.uix.pickers'라는 모듈이 없습니까?
- python : 프레임을 사용하지 않고 Tkinter 부드러운 창 변경
- python : PyQT에서 두 앱 간 전환
- python : KivyMD 도구 모음에 right_action_items를 추가할 수 없습니다.
- python : Raspberry-Pi 카메라 자동 감지
- python : tkinter 버튼을 사용하여 다른 스크립트 실행
그래서 몇 가지 빠진 것 같습니다 :
화면이 작동하려면 다음을 추가해야합니다.
와이즈 비즈 각 Screen 클래스 뒤에 모든 레이아웃과 위젯을 넣습니다.
또한 레이아웃을 화면에 추가하는 것을 잊었습니다.
와이즈 비즈
def __init__ (self,**kwargs):
의 끝에서self.add_widget(layout_coffee)