我们来理一下思路,首先导入几个PyQt5必要的库。
然后读取我们程序记录下来的错误,路径可以自己改。
然后把错误告诉给大家。
那个lb2是一个图标文件,路径可以自己改。
最后,调用一下窗口就好了。
try:
pass
except:
pass
else:
try:
#INFO
INFO="""
BugReport.pyw
"""
HTML='http://haote.home.cn/'
#Library
import os
import datetime
import sys
import subprocess
import pygame
import webbrowser
from PyQt5.QtGui import QIcon
from PyQt5.Qt import *
from PyQt5.QtCore import *
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import *
#Variables
NULL=''
#ReadErrors
with open('error.txt','r',encoding='utf-8') as readError:
error=readError.read()
#MainWindow
class Main(QMainWindow):
def __init__(self):
super().__init__()
self.ui()
self.flag=True
def ui(self):
#InitWindow
self.resize(400,200)
self.setWindowTitle('写作助手')
self.setFixedSize(self.width(),self.height())
self.setWindowIcon(QIcon('res\App_Icon\Application_Icon.ico'))
#UI
label=QLabel(self)
label.setText('程序中发生了一个错误(异常)。如下:')
label.setStyleSheet('font-size:16px;')
label.resize(280,20)
label.move(70,30)
label.show()
pic=QPixmap('res/App_Icon/error.png')
lb2 = QLabel(self)
lb2.setPixmap(pic)
lb2.resize(48,48)
lb2.setScaledContents(True)
lb2.move(25,23)
lb2.show()
textedit=QTextEdit(self)
textedit.setPlainText(error)
textedit.setReadOnly(True)
textedit.resize(230,100)
textedit.move(85,70)
textedit.setLineWrapMode(False)
textedit.show()
except Exception as exception:
with open('error.txt','a',encoding='utf-8') as exception_write:
exception_write.write('{0} {1}:{2}{3}'.format(os.getlogin(),datetime.datetime.now(),str(exception),'\n'))
#Applications
if __name__ == '__main__':
applications = QApplication(sys.argv)
root=Main()
root.show()
sys.exit(applications.exec_())