设计人员的PyQT5内部化支持

时间:2019-03-04 05:05:04

标签: python pyqt multilingual

我已经用设计器创建了表单,并将其转换为python代码。

形成main_ui.py

from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Form(object):
    def setupUi(self, Form):
        Form.setObjectName("Form")
        Form.resize(364, 135)
        self.save_btn = QtWidgets.QPushButton(Form)
        self.save_btn.setGeometry(QtCore.QRect(30, 30, 85, 27))
        self.save_btn.setObjectName("save_btn")
        self.cancel_btn = QtWidgets.QPushButton(Form)
        self.cancel_btn.setGeometry(QtCore.QRect(150, 30, 85, 27))
        self.cancel_btn.setObjectName("cancel_btn")
        self.send_btn = QtWidgets.QPushButton(Form)
        self.send_btn.setGeometry(QtCore.QRect(260, 30, 85, 27))
        self.send_btn.setObjectName("send_btn")
        self.en_btn = QtWidgets.QPushButton(Form)
        self.en_btn.setGeometry(QtCore.QRect(30, 80, 85, 27))
        self.en_btn.setObjectName("en_btn")
        self.pt_btn = QtWidgets.QPushButton(Form)
        self.pt_btn.setGeometry(QtCore.QRect(260, 80, 85, 27))
        self.pt_btn.setObjectName("pt_btn")
        self.es_btn = QtWidgets.QPushButton(Form)
        self.es_btn.setGeometry(QtCore.QRect(150, 80, 85, 27))
        self.es_btn.setObjectName("es_btn")

        self.retranslateUi(Form)
        QtCore.QMetaObject.connectSlotsByName(Form)

    def retranslateUi(self, Form):
        _translate = QtCore.QCoreApplication.translate
        Form.setWindowTitle(_translate("Form", "Form"))
        self.save_btn.setText(_translate("Form", "save"))
        self.cancel_btn.setText(_translate("Form", "cancel"))
        self.send_btn.setText(_translate("Form", "send"))
        self.en_btn.setText(_translate("Form", "EN"))
        self.pt_btn.setText(_translate("Form", "PT"))
        self.es_btn.setText(_translate("Form", "ES"))

添加main.py文件

import main_ui
import sys  # sys нужен для передачи argv в QApplication
from PyQt5 import QtWidgets, QtCore

class ExampleApp(QtWidgets.QMainWindow, main_ui.Ui_Form):
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        self.en_btn.clicked.connect(self.retr)
        self.pt_btn.clicked.connect(self.retr)
        self.es_btn.clicked.connect(self.retr)
    def retr(self):
        pass
def main():
    app = QtWidgets.QApplication(sys.argv)
    window = ExampleApp()
    window.show()
    app.exec_()
if __name__ == '__main__':  
    main()

我已经创建了一个简单的Form(来自设计器)。我想将“标签和按钮”的文本从英语翻译成西班牙语,葡萄牙语,反之亦然。

如何在那里实现,以及是否可以与Designer集成?

0 个答案:

没有答案