[python] view plain copy
import sys
import os
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
class Notepad(QMainWindow):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
openAction = QAction('Open', self)
openAction.setShortcut('Ctrl+O')
openAction.setStatusTip('Open a file')
openAction.triggered.connect(self.openFile)
closeAction = QAction('Close', self)
closeAction.setShortcut('Ctrl+Q')
closeAction.setStatusTip('Close Notepad')
closeAction.triggered.connect(self.close)
menubar = self.menuBar()
fileMenu = menubar.addMenu('&File')
fileMenu.addAction(openAction)
fileMenu.addAction(closeAction)
self.textEdit = QTextEdit(self)
self.textEdit.setFocus()
self.textEdit.setReadOnly(True)
self.resize(700, 800)
self.setWindowTitle('Notepad')
self.setCentralWidget(self.textEdit)
self.show()
def openFile(self):
filename, _ = QFileDialog.getOpenFileName(self, 'Open File', os.getenv('HOME'))
fh = ''
if QFile.exists(filename):
fh = QFile(filename)
if not fh.open(QFile.ReadOnly):
QtGui.qApp.quit()
data = fh.readAll()
codec = QTextCodec.codecForUtfText(data)
unistr = codec.toUnicode(data)
tmp = ('Notepad: %s' % filename)
self.setWindowTitle(tmp)
self.textEdit.setText(unistr)
def main():
app = QApplication(sys.argv)
notepad = Notepad()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
这个很简单啊 真的是很简单 很简单 在开始菜单下方的输入框输入 pyuic4 -o ui_xxx.py xxx.ui 将 ui_xxx.py 替换为要生成的 **.py文件(包含路径)(一般都保留前面的ui_) xxx.ui 替换为要编译的 **.ui 文件(包含路径)欢迎分享,转载请注明来源:内存溢出
评论列表(0条)