我有一个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_())
答案 0 :(得分: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()