#Изначально подключаются необходимые библиотеки #from graphics import * from PyQt5 import QtCore, QtGui, QtWidgets import sys from Shift import Ui_Form if __name__ == "__main__":\ app = QtWidgets.QApplication(sys.argv) #Следующий код отвечает за открытие интерфейса Form = QtWidgets.QWidget() ui = Ui_Form() ui.setupUi(Form) Form.show() #Процедура замены символов методом "Атбаш" def shift(): intab = 'абвгдежзийклмнопрстуфхцчшщъыьэюя АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ' outtab = 'яюэьыъщшчцхфутсрпонмлкйизжедгвба5ЯЭЮЬЫЪЩШЧЦХФУТСРПОНМЛКЙИЗЖЕДГВБА' ui.pushButton_3.close() trans = ui.lineEdit.text() ui.lineEdit_2.setText(trans.translate(str.maketrans(intab, outtab))) ui.pushButton.clicked.connect(shift) #Выход из приложения sys.exit(app.exec_()) # Так как программа закрывается сразу же после ее запуска, то пришлось оставить строчку для ввода input(" Нажмите для выхода ... ")
Файл с интерфейсом
# -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'C:\python\Lib\site-packages\PySide2\Shifr.ui' # # Created by: PyQt5 UI code generator 5.14.2 # # WARNING! All changes made in this file will be lost! from PyQt5 import QtCore, QtGui, QtWidgets class Ui_Form(object): def setupUi(self, Form): Form.setObjectName("Form") Form.resize(618, 538) Form.setStyleSheet("background-color: rgb(243, 239, 255);") self.lineEdit = QtWidgets.QLineEdit(Form) self.lineEdit.setGeometry(QtCore.QRect(0, 50, 621, 121)) self.lineEdit.setLayoutDirection(QtCore.Qt.LeftToRight) self.lineEdit.setStyleSheet("QLineEdit:hover{\n" " background-color:white;\n" "}") self.lineEdit.setText("") self.lineEdit.setCursorPosition(0) self.lineEdit.setAlignment(QtCore.Qt.AlignCenter) self.lineEdit.setDragEnabled(False) self.lineEdit.setReadOnly(False) self.lineEdit.setObjectName("lineEdit") self.lineEdit_2 = QtWidgets.QLineEdit(Form) self.lineEdit_2.setGeometry(QtCore.QRect(0, 330, 621, 131)) self.lineEdit_2.setStyleSheet("QLineEdit:hover{\n" " background-color:white;\n" "}") self.lineEdit_2.setText("") self.lineEdit_2.setCursorPosition(0) self.lineEdit_2.setAlignment(QtCore.Qt.AlignCenter) self.lineEdit_2.setObjectName("lineEdit_2") self.label = QtWidgets.QLabel(Form) self.label.setGeometry(QtCore.QRect(250, 9, 131, 31)) self.label.setStyleSheet("QLabel:hover {\n" " font: 14pt \"Segoe Print\";\n" " color:red;\n" "}") self.label.setObjectName("label") self.label_2 = QtWidgets.QLabel(Form) self.label_2.setGeometry(QtCore.QRect(200, 280, 241, 31)) self.label_2.setStyleSheet("QLabel:hover{\n" " color: red;\n" "}") self.label_2.setObjectName("label_2") self.pushButton = QtWidgets.QPushButton(Form) self.pushButton.setGeometry(QtCore.QRect(230, 200, 171, 61)) self.pushButton.setStyleSheet("QPushButton {\n" " background-color:grey;\n" " border:none;\n" " color:white;\n" " font-size: 20px;\n" " font-weight:bold;\n" "}\n" "QPushButton:hover{\n" " background-color:white;\n" " color:black;\n" "}") self.pushButton.setAutoRepeat(False) self.pushButton.setAutoExclusive(False) self.pushButton.setAutoDefault(False) self.pushButton.setDefault(False) self.pushButton.setFlat(False) self.pushButton.setObjectName("pushButton") self.pushButton_2 = QtWidgets.QPushButton(Form) self.pushButton_2.setGeometry(QtCore.QRect(0, 200, 181, 61)) self.pushButton_2.setStyleSheet("QPushButton {\n" " background-color:grey;\n" " border:none;\n" " color:white;\n" " font-size: 20px;\n" " font-weight:bold;\n" "}\n" "QPushButton:hover{\n" " background-color:white;\n" " color:black;\n" "}") self.pushButton_2.setObjectName("pushButton_2") self.pushButton_3 = QtWidgets.QPushButton(Form) self.pushButton_3.setGeometry(QtCore.QRect(380, 470, 241, 71)) self.pushButton_3.setStyleSheet("QPushButton {\n" " background-color:grey;\n" " border:none;\n" " color:white;\n" " font-size: 20px;\n" " font-weight:bold;\n" "}\n" "QPushButton:hover{\n" " background-color:white;\n" " color:black;\n" "}") self.pushButton_3.setObjectName("pushButton_3") self.retranslateUi(Form) QtCore.QMetaObject.connectSlotsByName(Form) def retranslateUi(self, Form): _translate = QtCore.QCoreApplication.translate Form.setWindowTitle(_translate("Form", "Атбаш")) self.label.setText(_translate("Form", "<html><head/><body><p align=\"justify\"><span style=\" font-size:14pt;\">Введите текст</span></p></body></html>")) self.label_2.setText(_translate("Form", "<html><head/><body><p align=\"justify\"><span style=\" font-size:14pt;\">Результат преобразования</span></p></body></html>")) self.pushButton.setText(_translate("Form", "Выполнить")) self.pushButton_2.setText(_translate("Form", "Очистить поля")) self.pushButton_3.setText(_translate("Form", "Закрыть программу"))