码迷,mamicode.com
首页 > Windows程序 > 详细

pyqt MainWindow记录内容

时间:2014-07-30 23:47:35      阅读:421      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   os   io   for   2014   

class Texts(QtGui.QMainWindow,Ui_MainWindow):

    def __init__(self,parne=None):

        super(Texts,self).__init__(parne)

        self.setupUi(self)

        self.setWindowTitle(u‘文档或者其他‘)

        self.setWindowIcon((QtGui.QIcon(r‘i/e.jpg‘)))

        self.setFixedSize(500,550)

        self.action_3_clear.setEnabled(False)

        self.showtext.setEnabled(False)

        self.adjustSize()

        import random

        rand1=‘#FFFFFF‘

        rand2=‘#000099‘

        self.showtext.setStyleSheet(""

                "color: %s;"

                "margin: 10px;"

                "padding: 5px;"

                "padding-left: 15px;"

                "padding-right: 15px;"

                "border-radius: 5px;"

                "border: 3px solid #abc;"%(rand1,rand2))

        self.showtext.setReadOnly(True)

        self.showtext.setEnabled(True)

        self.setWindowIcon(QtGui.QIcon(r‘i/e.png‘))

        self.action_3_about.triggered.connect(self.aboutn)

        self.action_close.triggered.connect(self.close_)

        self.action_file.triggered.connect(self.openflies)

        self.action_3_clear.triggered.connect(self.qingkong_)

        self.showtext.textChanged.connect(self.updatea)

    def aboutn(self):

        QtGui.QMessageBox.information(self,u‘关于‘,u‘这部分是文档或者文本部分,用于查看有关内容的地方‘)

    def close_(self):

        self.close()

    def openflies(self):

        self.showtext.setEnabled(True)

        fileName=QtGui.QFileDialog.getOpenFileName(self)

        if fileName.isEmpty()==False:

            if self.showtext.document().isEmpty():

                self.loadFile(fileName)

    def loadFile(self,fileName):

        file=QtCore.QFile(fileName)

        if file.open(QtCore.QIODevice.ReadOnly|QtCore.QIODevice.Text):

            textStream=QtCore.QTextStream(file)

            while textStream.atEnd()==False:

                self.showtext.appendPlainText(textStream.readLine())

    def qingkong_(self):

        close1=QtGui.QMessageBox(self)

        close1.setWindowTitle(u‘清空选项‘)

        close1.setWindowIcon(QtGui.QIcon(r‘i/a.png‘))

        yes=close1.addButton(u‘清空(&Yes)‘,QtGui.QMessageBox.ActionRole)

        no=close1.addButton(u‘(&No)‘,QtGui.QMessageBox.ActionRole)

        close1.setText(u‘您真的要退出这个工具吗?‘)

        close1.exec_()

        button=close1.clickedButton()

        if button==yes:

            self.showtext.clear()

        else:pass

    def updatea(self):

        self.action_3_clear.setEnabled(self.showtext.toPlainText().isEmpty()==False)

        self.showtext.setEnabled(True)

如图:bubuko.com,布布扣

pyqt MainWindow记录内容,布布扣,bubuko.com

pyqt MainWindow记录内容

标签:style   blog   http   color   os   io   for   2014   

原文地址:http://www.cnblogs.com/mhxy13867806343/p/3879391.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!