求推荐适用于Raspbian的信息亭式只读UI开发框架
Great question—let's break down the top community-endorsed tools that fit your exact requirements for a lightweight, read-only kiosk interface on Raspbian, while avoiding the bloat of overkill frameworks like full game engines or heavy desktop GUI toolkits.
1. PyQt5/PySide2 (Qt for Python)
This is hands-down the most popular choice in the Raspbian/embedded Linux community for kiosk-style UIs. It’s lightweight, highly customizable, and checks all your boxes with minimal overhead:
- Fullscreen mode: Easily enable borderless fullscreen with
QWidget.showFullScreen(), and you can hide the system cursor withQt.BlankCursorto eliminate distractions. - Non-raster fonts: Qt natively supports TTF/OTF fonts—just load your desired font file with
QFont("/path/to/your/font.ttf", size)and apply it to any text element. - Geometry/SVG support: Use
QPainterto draw lines, rectangles, circles, and other shapes directly on the canvas. For SVG,QSvgWidgetlets you load and render vector graphics seamlessly. - Canvas rotation: Leverage
QTransformto rotate the entire drawing context (or individual elements) to any angle. For example, rotating the canvas 90 degrees around its center takes just a few lines of code.
Raspbian includes pre-built packages for PyQt5, so installation is trivial: sudo apt install python3-pyqt5.
Quick Example Code
import sys from PyQt5.QtWidgets import QApplication, QWidget from PyQt5.QtGui import QPainter, QFont, QColor, QTransform from PyQt5.QtCore import Qt class KioskDisplay(QWidget): def __init__(self): super().__init__() # Enable fullscreen, no borders, hidden cursor self.showFullScreen() self.setCursor(Qt.BlankCursor) self.setStyleSheet("background: #000;") # Black background for kiosk # Load a custom TTF font self.kiosk_font = QFont("/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf", 32) def paintEvent(self, event): painter = QPainter(self) # Rotate canvas 90 degrees (center origin) center = self.rect().center() painter.translate(center.x(), center.y()) painter.rotate(90) painter.translate(-center.x(), -center.y()) # Draw text with custom font painter.setFont(self.kiosk_font) painter.setPen(QColor(Qt.white)) painter.drawText(200, 200, "Raspberry Pi Kiosk") # Draw basic shapes painter.setPen(QColor(Qt.red)) painter.drawLine(100, 100, 400, 100) # Horizontal line painter.drawEllipse(250, 250, 100, 100) # Circle if __name__ == "__main__": app = QApplication(sys.argv) display = KioskDisplay() sys.exit(app.exec_())
2. SDL2 (with SDL_ttf & SDL_image)
If you prefer lower-level control or want to work in C/C++ (or even Python via pygame_sdl2), SDL2 is a fantastic lightweight option optimized for embedded systems. It’s far less bloated than PyGame while still covering all your needs:
- Fullscreen: Use
SDL_SetWindowFullscreen()with theSDL_WINDOW_FULLSCREEN_DESKTOPflag to enable borderless fullscreen. - Font rendering: SDL_ttf handles TTF/OTF fonts, letting you render text directly to the screen surface.
- Geometry/SVG: Draw lines, rectangles, and polygons with
SDL_RenderDrawLine()and similar functions. SDL_image adds support for SVG (along with other image formats) when built with the right dependencies. - Rotation:
SDL_RenderCopyEx()lets you rotate textures (including the entire screen surface) to any angle around a pivot point.
Install on Raspbian with: sudo apt install libsdl2-dev libsdl2-ttf-dev libsdl2-image-dev.
3. EFL (Enlightenment Foundation Libraries)
EFL is a lesser-known but highly respected framework built specifically for embedded and resource-constrained systems. Its Elementary UI toolkit is perfect for read-only kiosks:
- Fullscreen: Elementary windows can be set to fullscreen with no decorations via simple API calls.
- Font support: EFL’s Evas canvas natively supports TTF/OTF fonts and system font management.
- Graphics: Draw basic shapes with Evas’ drawing API, or load SVG files directly into the canvas.
- Rotation: Evas provides transformation functions to rotate the entire canvas or individual elements to any orientation.
Install on Raspbian with: sudo apt install libefl-dev python3-efl.
Why Your Previous Options Aren’t Ideal (Per Community Consensus)
- Tkinter: While functional, it’s designed for desktop GUI controls (buttons, text boxes) rather than lightweight canvas-based displays. Fullscreen setup and canvas rotation are clunky, and it’s rarely recommended for kiosk use in the Raspbian community.
- PyGame: As you noted, it’s a full game engine with tons of unused features (audio input, collision detection) that add unnecessary overhead. While fullscreen/rotation is possible, the community generally prefers lighter tools for static kiosk displays.
- GTK#: The Mono dependency adds significant bloat. If you like C#, consider using GTK3 with
gtk-sharp3instead—but even then, Qt’s canvas rotation and SVG support are more intuitive for kiosk use cases.
Final Recommendation
The community best practice for your use case is PyQt5. It strikes the perfect balance between ease of use, feature completeness, and lightweight performance on Raspbian. It’s well-documented, has a large user base for troubleshooting, and requires no extra heavy dependencies beyond what’s already available in Raspbian’s repositories.
内容的提问来源于stack exchange,提问作者Mark A. Donohoe

