pyqt5寫的摩斯密碼

袁少澤發表於2020-12-06
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'QMainwindowUI.ui'
#
# Created by: PyQt5 UI code generator 5.15.0
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again.  Do not edit this file unless you know what you are doing.


from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(417, 359)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.pushButton = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton.setGeometry(QtCore.QRect(0, 240, 151, 23))
        self.pushButton.setObjectName("pushButton")
        self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton_2.setGeometry(QtCore.QRect(290, 100, 101, 23))
        self.pushButton_2.setObjectName("pushButton_2")
        self.pushButton_3 = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton_3.setGeometry(QtCore.QRect(290, 150, 101, 23))
        self.pushButton_3.setObjectName("pushButton_3")
        self.widget = QtWidgets.QWidget(self.centralwidget)
        self.widget.setGeometry(QtCore.QRect(1, 24, 281, 171))
        self.widget.setObjectName("widget")
        self.gridLayout = QtWidgets.QGridLayout(self.widget)
        self.gridLayout.setContentsMargins(0, 0, 0, 0)
        self.gridLayout.setObjectName("gridLayout")
        self.radioButton = QtWidgets.QRadioButton(self.widget)
        self.radioButton.setChecked(False)
        self.radioButton.setObjectName("radioButton")
        self.gridLayout.addWidget(self.radioButton, 0, 0, 1, 1)
        self.radioButton_2 = QtWidgets.QRadioButton(self.widget)
        self.radioButton_2.setCheckable(True)
        self.radioButton_2.setChecked(False)
        self.radioButton_2.setObjectName("radioButton_2")
        self.gridLayout.addWidget(self.radioButton_2, 0, 1, 1, 1)
        self.lineEdit = QtWidgets.QLineEdit(self.widget)
        self.lineEdit.setObjectName("lineEdit")
        self.gridLayout.addWidget(self.lineEdit, 1, 0, 1, 2)
        self.label = QtWidgets.QLabel(self.widget)
        self.label.setObjectName("label")
        self.gridLayout.addWidget(self.label, 2, 0, 1, 2)
        self.label_2 = QtWidgets.QLabel(self.widget)
        self.label_2.setEnabled(True)
        self.label_2.setMouseTracking(False)
        self.label_2.setTabletTracking(True)
        self.label_2.setAcceptDrops(False)
        self.label_2.setToolTip("")
        self.label_2.setAutoFillBackground(True)
        self.label_2.setScaledContents(False)
        self.label_2.setWordWrap(False)
        self.label_2.setObjectName("label_2")
        self.gridLayout.addWidget(self.label_2, 3, 0, 1, 2)
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 417, 21))
        self.menubar.setObjectName("menubar")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

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

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "摩斯密碼"))
        MainWindow.setToolTip(_translate("MainWindow", "袁少澤最帥"))
        self.pushButton.setText(_translate("MainWindow", "開始"))
        self.pushButton_2.setText(_translate("MainWindow", "複製label"))
        self.pushButton_3.setText(_translate("MainWindow", "複製label_2"))
        self.radioButton.setText(_translate("MainWindow", "加密"))
        self.radioButton_2.setToolTip(_translate("MainWindow", "解密只能用label_2"))
        self.radioButton_2.setText(_translate("MainWindow", "解密"))
        self.lineEdit.setPlaceholderText(_translate("MainWindow", "只能輸入數字字母和空格"))
        self.label.setText(_translate("MainWindow", "label"))
        self.label_2.setText(_translate("MainWindow", "label_2"))


import sys
from PyQt5.QtWidgets import *
import pyperclip

direct_keys=['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
             'Q', 'R', 'S', 'T', 'U', 'V',
             'W', 'X', 'Y', 'Z', ' ', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0']
direct_values=['.-', '-...', '- .-.', '- ..', '.', '..-.', '--.', '....', '..', '.━ ━ ━', '━.',
               '-..', '-', '-.', '---', '.--.', '--.-', '.-.', '...', '-', '..-',
               '...-', '.--', '-..-', '-.--', '--..', '  ', '----', '. .---',
               '. . .--', '. . . .-',
               '. . . . .', '-. . . .', '--. . .', '---. .', '----.', '-----']
def jiami(miwen):
    list1 = []
    for i in miwen.upper():
        list1.append(direct_values[direct_keys.index(i)])
    return ''.join(list1)
def jiami_2(miwen):
    list3 = []
    for i in miwen.upper():
        list3.append(direct_values[direct_keys.index(i)])
    return '/'.join(list3)
def jiemi(miwen):
    list2 = []
    list4 = []
    list2=miwen.split('/')
    for i in list2:
        list4.append(direct_keys[direct_values.index(i)])
    return ''.join(list4)
class win(QMainWindow):
    def __init__(self):
        super(win, self).__init__()
        self.initUI()
        self.caoradioButton()

    def initUI(self):
        # self.ui=uic.loadUi('QMainwindowUI.ui')
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

        self.ui.pushButton.clicked.connect(self.caoradioButton)
        self.ui.pushButton_2.clicked.connect(self.caobtn2)
        self.ui.pushButton_3.clicked.connect(self.caobtn3)
    def caoradioButton(self):
        if self.ui.radioButton.isChecked() == True:
            self.ui.label.setText(jiami(self.ui.lineEdit.text()))
            self.ui.label_2.setText(jiami_2(self.ui.lineEdit.text()))
        elif self.ui.radioButton_2.isChecked() == True:
            print(self.ui.lineEdit.text())
            self.ui.label.setText(jiemi(str(self.ui.lineEdit.text())))
            self.ui.label_2.setText('製作者QQ:1653490853 ')
    def caobtn2(self):
        pyperclip.copy(self.ui.label.text())
    def caobtn3(self):
        pyperclip.copy(self.ui.label_2.text())
if __name__ == '__main__':
    app = QApplication(sys.argv)
    main = win()
    main.show()
    sys.exit(app.exec_())

 

相關文章