使用Python PyQt5制作文本编辑器
立即下载
资源介绍:
这是一个使用Python的PyQt5制作的文本编辑器,是以open函数的基础上加了Qt的gui制作的软件。这个软件有新建和打开功能:点击新建会有创建窗口,创建完后即可打字;点击打开会有打开窗口,选择后会直接进入打字界面。上方有文件,编辑两个按钮,里面的选项自行查看。这是我两年前四年级的作品,所以做的不太好,不喜勿喷。如果有良心博主,可以二创艾特我。
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'C:\Users\Administrator\Documents\edit_in_txt\edit_in_txt1.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
#
# 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
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
import sqlite3, os
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(721, 405)
MainWindow.setWindowIcon(QIcon('images/file.ico'))
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.textEdit = QtWidgets.QTextEdit(self.centralwidget)
self.textEdit.setGeometry(QtCore.QRect(0, 80, 721, 271))
font1 = QtGui.QFont()
font1.setFamily("晴圆")
font1.setPointSize(20)
self.textEdit.setFont(font1)
self.textEdit.setObjectName("textEdit")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(3, 1, 481, 71))
font = QtGui.QFont()
font.setFamily("晴圆")
font.setPointSize(29)
self.label.setFont(font)
self.label.setObjectName("label")
MainWindow.setCentralWidget(self.centralwidget)
self.menuBar = QtWidgets.QMenuBar(MainWindow)
self.menuBar.setGeometry(QtCore.QRect(0, 0, 721, 23))
self.menuBar.setLayoutDirection(QtCore.Qt.LeftToRight)
self.menuBar.setObjectName("menuBar")
self.menu2 = QtWidgets.QMenu(self.menuBar)
self.menu2.setEnabled(True)
font = QtGui.QFont()
font.setBold(False)
font.setWeight(50)
self.menu2.setFont(font)
self.menu2.setToolTipDuration(-2)
self.menu2.setLayoutDirection(QtCore.Qt.LeftToRight)
self.menu2.setTearOffEnabled(False)
self.menu2.setObjectName("menu2")
self.menu = QtWidgets.QMenu(self.menuBar)
self.menu.setObjectName("menu")
MainWindow.setMenuBar(self.menuBar)
self.statusBar = QtWidgets.QStatusBar(MainWindow)
self.statusBar.setObjectName("statusBar")
MainWindow.setStatusBar(self.statusBar)
self.copy = QtWidgets.QAction(MainWindow)
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap("images/copy.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.copy.setIcon(icon)
self.copy.setObjectName("copy")
self.paste = QtWidgets.QAction(MainWindow)
icon1 = QtGui.QIcon()
icon1.addPixmap(QtGui.QPixmap("images/paste.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.paste.setIcon(icon1)
self.paste.setObjectName("paste")
self.cut = QtWidgets.QAction(MainWindow)
icon2 = QtGui.QIcon()
icon2.addPixmap(QtGui.QPixmap("images/cut.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.cut.setIcon(icon2)
self.cut.setObjectName("cut")
self.undo = QtWidgets.QAction(MainWindow)
icon3 = QtGui.QIcon()
icon3.addPixmap(QtGui.QPixmap("images/undo.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.undo.setIcon(icon3)
self.undo.setObjectName("undo")
self.redo = QtWidgets.QAction(MainWindow)
icon4 = QtGui.QIcon()
icon4.addPixmap(QtGui.QPixmap("images/redo.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.redo.setIcon(icon4)
self.redo.setObjectName("redo")
self.add1 = QtWidgets.QAction(MainWindow)
icon5 = QtGui.QIcon()
icon5.addPixmap(QtGui.QPixmap("images/add.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.add1.setIcon(icon5)
self.add1.setObjectName("add1")
self.open1 = QtWidgets.QAction(MainWindow)
icon6 = QtGui.QIcon()
icon6.addPixmap(QtGui.QPixmap("images/open.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.open1.setIcon(icon6)
self.open1.setObjectName("open1")
self.rename = QtWidgets.QAction(MainWindow)
icon7 = QtGui.QIcon()
icon7.addPixmap(QtGui.QPixmap("images/rename.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.rename.setIcon(icon7)
self.rename.setObjectName("rename")
self.clean = QtWidgets.QAction(MainWindow)
icon8 = QtGui.QIcon()
icon8.addPixmap(QtGui.QPixmap("images/clear.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
icon9 = QtGui.QIcon()
icon9.addPixmap(QtGui.QPixmap("images/save.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.save = QtWidgets.QAction(MainWindow)
self.save.setIcon(icon9)
self.save.setObjectName("open1")
self.clean.setIcon(icon8)
self.clean.setObjectName("clean")
self.menu2.addAction(self.copy)
self.menu2.addAction(self.paste)
self.menu2.addAction(self.cut)
self.menu2.addAction(self.clean)
self.menu.addAction(self.save)
self.menu2.addSeparator()
self.menu2.addAction(self.undo)
self.menu2.addAction(self.redo)
self.menu.addAction(self.add1)
self.menu.addAction(self.open1)
self.menu.addSeparator()
self.menu.addAction(self.rename)
self.menuBar.addAction(self.menu.menuAction())
self.menuBar.addAction(self.menu2.menuAction())
sqlsys2 = sqlite3.connect('mosoft/mrsoft.db')
cusuor2 = sqlsys2.cursor()
cusuor2.execute('select * from user')
self.b = cusuor2.fetchone()
name2 = self.b[1]
if name2=='':
self.init = 'None'
else:
self.init = name2
file1 = open(self.init, 'r', encoding='utf-8')
filetext = file1.read()
self.textEdit.setText(filetext)
file1.close()
cusuor2.close()
sqlsys2.commit()
sqlsys2.close()
self.retranslateUi(MainWindow)
self.copy.triggered.connect(self.textEdit.copy)
self.cut.triggered.connect(self.textEdit.cut)
self.clean.triggered.connect(self.textEdit.clear)
self.redo.triggered.connect(self.textEdit.redo)
self.undo.triggered.connect(self.textEdit.undo)
self.add1.triggered.connect(self.add2)
self.open1.triggered.connect(self.open2)
self.rename.triggered.connect(self.rename2)
self.save.triggered.connect(self.save1)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "编辑器"))
self.label.setText(_translate("MainWindow", "TXT编辑器"))
self.menu2.setTitle(_translate("MainWindow", "编辑"))
self.menu.setTitle(_translate("MainWindow", "文件"))
self.copy.setText(_translate("MainWindow", "复制(&C)"))
self.paste.setText(_translate("MainWindow", "粘贴(&V)"))
self.paste.setShortcut(_translate("MainWindow", "Ctrl+V"))
self.cut.setText(_translate("MainWindow", "剪切(&X)"))
self.cut.setShortcut(_translate("MainWindow", "Ctrl+X"))
self.undo.setText(_translate("MainWindow", "撤销(&Z)"))
self.undo.setShortcut(_translate("MainWindow", "Ctrl+Z"))
self.redo.setText(_translate("MainWindow", "重做(&R)"))
self.redo.setShortcut(_translate("MainWindow", "Ctrl+Shift+Z"))
self.add1.setText(_translate("MainWindow", "新建(&N)"))
self.add1.setShortcut(_translate("MainWindow", "Ctrl+N"))
self.open1.setText(_translate("MainWindow", "打开(&O)"))
self.open1.setShortcut(_translate("MainWindow", "Ctrl+O"))
self.rename.setText(_translate("MainWind