-1

我有一个 Python 类,它显示一个包含 2 个文本字段和 2 个按钮的窗口。

用户在第一个编辑文本中输入字符串并单击(打开按钮)时,第二个编辑文本将显示用户输入。

问题是单击按钮时,文本字段中没有显示任何内容。

代码:

'''
1- import the libraries from the converted file
2- import the converted file 
'''
from PyQt5 import QtCore, QtGui, QtWidgets
import pathmsgbox 
import os 
import pathlib

class path_window(pathmsgbox.Ui_PathMSGbox):


    def __init__(self,windowObject ):
        self.windowObject = windowObject
        self.setupUi(windowObject)
        self.windowObject.show()
        self.getText()


    '''
    get the userInput  from the EditLine
    '''   

    def getText(self):
        inputUser = self.pathEditLine.text()
        outPutUser = self.outputPathName.setText(inputUser)
        print(outPutUser)

    def puchBtn(self):
        openButton = self.PathOpenBtn.clicked.connect(self.getText)    
'''
function that exit from the system after clicking "cancel"
'''
def exit():
    sys.exit()

'''
define the methods to run only if this is the main module deing run
the name take __main__ string only if its the main running script and not imported 
nor being a child process
'''
if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    PathMSGbox = QtWidgets.QWidget()
    pathUi = path_window(PathMSGbox)
    pathUi.pathCancelBtn.clicked.connect(exit)
    sys.exit(app.exec_())
4

1 回答 1

0

您没有将单击的按钮事件连接到函数 - 绑定位于从未调用过的函数中。

只需在类初始化中连接您的按钮:

class path_window(pathmsgbox.Ui_PathMSGbox):


    def __init__(self,windowObject ):
        self.windowObject = windowObject
        self.setupUi(windowObject)
        self.windowObject.show()
        self.PathOpenBtn.clicked.connect(self.getText)
        self.getText()
于 2018-03-17T15:54:59.770 回答