美文网首页
记一次 GUI编程 PYqt5

记一次 GUI编程 PYqt5

作者: 垃圾桶边的狗 | 来源:发表于2021-03-21 13:56 被阅读0次
import sys

from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QHBoxLayout, QLineEdit, QFormLayout, QFileDialog, \
    QTextBrowser


class A(QWidget):


    def __init__(self, parent=None):
        QWidget.__init__(self, parent)

        self.TT = QLineEdit()

        self.setWindowTitle("title")

        self.TAE_Mapping_File = QLineEdit()

        self._initUi()

    def _initUi(self):
        btn = QPushButton()

        self.TAE_Mapping_File.setPlaceholderText('哈哈')

        basic_layout = QFormLayout()

        row1_layout = QFormLayout()

        row1_layout.addWidget(btn)

        row1_layout.addwidget(self.TAE_Mapping_File)

        basic_layout.addRow('row 1', row1_layout)

        self.setLayout(basic_layout)

        btn.clicked.connect(self.ttt)

    def ttt(self):
        f_name = QFileDialog.get0penFileName(self, 'Select Mapping File')  # filter='Excel Files(*.map) '

        print(f_name)

        self.TT.setText(f_name[0])

        self.TT.insert(",123")


class ToolUI(QWidget):

    def __init__(self, parent=None):
        self.text = ''

        QWidget.__init__(self, parent)

        self.resize(400, 500)

        self.TAE_Excel_File = QLineEdit()

        self.UI_Text_Browser = QTextBrowser(self)

        self.setWindowTitle('title')

        self.TAE_Mapping_File = QLineEdit()

        self.button1 = QPushButton("确定")

        # self.button 1.set Maximum Width(50)

        self.Button_TAE_Mapping = QPushButton("选择文件")

        self.button1.clicked.connect(self.on_clinck)

        self._initUI()

    def _initUI(self):
        self.TAE_Mapping_File.setPlaceholderText(u'点击按钮选择')
        ECU_Name = QLineEdit()
        ECU_Name.setPlaceholderText(u'start')
        ECU_Name1 = QLineEdit()
        ECU_Name1.setPlaceholderText(u'end')
        basic_layout = QFormLayout()
        Row1_layout = QHBoxLayout()
        Row1_layout.addWidget(self.Button_TAE_Mapping)
        Row1_layout.addWidget(self.TAE_Mapping_File)
        Row4_layout = QHBoxLayout()
        Row4_layout.addWidget(ECU_Name)
        Row4_layout.addWidget(ECU_Name1)
        basic_layout.addRow('<h4>s19文件</h4>', Row1_layout)
        basic_layout.addRow(u'<h3>start-end</h3>', Row4_layout)
        basic_layout.addRow(self.button1)

        basic_layout.addRow(self.UI_Text_Browser)
        self.setLayout(basic_layout)
        self.Button_TAE_Mapping.clicked.connect(self.GetMappingFilePath)
        ECU_Name.textChanged.connect(self.FetchStart)
        ECU_Name1.textChanged.connect(self.FetchEnd)


    def FetchStart(self,text):
        if text!='':
            self.text=text
            #self.UI_Text_Browser.append("<fontcolor='black'S"+{0} '.format(self.text) )
    def FetchEnd(self, text):

        if text!='':
            self.text1=text
            #self.UI_Text_Browser.append("<fontcolor='black'>"+1111:{0} '.format(self.text 1) )
    def GetMappingFilePath(self):
        f_name=QFileDialog.getOpenFileName(self,'Select Mapping File')
        if f_name[0]:
            #通过分隔符切割函数split获取map文件名, 放入到UI面板中“Mapping文件"的窗口中
            self.TAE_Mapping_File.setText(f_name[0] )
            #将文件路径显示在UI的总信息提示窗口中



    def keyPressEvent(self,QKeyEvent):
        print(QKeyEvent.key(),'afs')
        if QKeyEvent.key() ==16777220:
            print('回车快捷键')

    def on_clinck(self):
        print(self.text, '[[[')
        print(self.text1, '====')
        self.button1.setDisabled(True)
        self.Button_TAE_Mapping.setDisabled(True)
        self.UI_Text_Browser.append("<font color='black'>"+'{0} :{1} '.format(self.text, self.text1))

app=QApplication(sys.argv)
ui=ToolUI()
ui.show()
app.exec()
sys.exit()

123sfcvcxv.png

官网
不知道

相关文章

网友评论

      本文标题:记一次 GUI编程 PYqt5

      本文链接:https://www.haomeiwen.com/subject/bgincltx.html