A lightweight and easy-to-use library for automating the translation of PyQt5 widgets.
Project description
PyQt5 Auto Translate
pyqt5_auto_translate
是一个用于 PyQt5 的自动翻译库,使您可以轻松地在 PyQt5 程序中实现多语言支持。您可以在几乎不修改原有代码的情况下增加多语言翻译支持.
安装
使用 pip 安装:
pip install pyqt5_auto_translate
目前支持翻译的组件
原始组件 | 支持翻译的组件 |
---|---|
QLabel | TranslatedQLabel |
QPushButton | TranslatedQPushButton |
QCheckBox | TranslatedQCheckBox |
QMenu | TranslatedQMenu |
QAction | TranslatedQAction |
示例
这里是一个没有集成翻译的代码:
import sys
from PyQt5.QtCore import Qt, QTimer
from PyQt5.QtWidgets import (
QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout, QLabel,
QLineEdit, QPushButton, QProgressBar, QSlider, QLCDNumber, QGroupBox
)
class ExampleUI(QWidget):
def __init__(self):
super().__init__()
# Initialize main layout
self.layout = QVBoxLayout()
# Add title label
self.title_label = QLabel("Example UI")
self.layout.addWidget(self.title_label)
# Add horizontal layout
self.hbox_layout = QHBoxLayout()
self.layout.addLayout(self.hbox_layout)
# Add label to horizontal layout
self.hbox_layout.addWidget(QLabel("Username: "))
# Add line edit to horizontal layout
self.username_input = QLineEdit()
self.hbox_layout.addWidget(self.username_input)
# Add another horizontal layout
self.hbox_layout2 = QHBoxLayout()
self.layout.addLayout(self.hbox_layout2)
# Add label to horizontal layout
self.hbox_layout2.addWidget(QLabel("Password: "))
# Add line edit to horizontal layout
self.password_input = QLineEdit()
self.password_input.setEchoMode(QLineEdit.Password)
self.hbox_layout2.addWidget(self.password_input)
# Add button
self.submit_button = QPushButton("Submit")
self.layout.addWidget(self.submit_button)
# Add progress bar
self.progress_bar = QProgressBar()
self.progress_bar.setRange(0, 100)
self.layout.addWidget(self.progress_bar)
# Add slider
self.slider = QSlider(Qt.Horizontal)
self.layout.addWidget(self.slider)
# Add LCD number
self.lcd_number = QLCDNumber()
self.lcd_number.setSegmentStyle(QLCDNumber.Flat)
self.layout.addWidget(self.lcd_number)
# Add timer
self.timer = QTimer()
self.timer.timeout.connect(self.update_progress_bar)
# Add group box
self.group_box = QGroupBox("Options")
self.group_box_layout = QVBoxLayout()
self.group_box.setLayout(self.group_box_layout)
# Add checkboxes to group box
self.checkbox1 = QPushButton("Option 1")
self.checkbox2 = QPushButton("Option 2")
self.checkbox3 = QPushButton("Option 3")
self.group_box_layout.addWidget(self.checkbox1)
self.group_box_layout.addWidget(self.checkbox2)
self.group_box_layout.addWidget(self.checkbox3)
# Add group box to layout
self.layout.addWidget(self.group_box)
# Set layout
self.setLayout(self.layout)
def start_timer(self):
self.timer.start(50)
def stop_timer(self):
self.timer.stop()
def update_progress_bar(self):
value = self.progress_bar.value() + 1
self.progress_bar.setValue(value)
self.lcd_number.display(value)
if __name__ == '__main__':
app = QApplication(sys.argv)
window = QMainWindow()
ui = ExampleUI()
window.setCentralWidget(ui)
window.show()
ui.start_timer()
sys.exit(app.exec_())
集成翻译功能:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for pyqt5_auto_translate-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | d70acfe7e1c64d69e2c3dbb23a8e01eab6840fa4894aacf2bf2363bd1eca2983 |
|
MD5 | d4d97eeb2c26932a1782d736f8edd212 |
|
BLAKE2b-256 | 3bae5d011aa98b70d8da2f18485f066a1a54d68e8f4a255a38a150b9b2e90ae4 |
Close
Hashes for pyqt5_auto_translate-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d7a5e94abbe3e0be2278b45503e89ee512ddda30743b84dc7b7b4f01838a591b |
|
MD5 | 98476714348a25cd240ef763be2db712 |
|
BLAKE2b-256 | 20e9ff3685e56904984625dda59a64489e5c18d1d233a7f2f1867843d6fd9f24 |