Python ) self.filename=fname[0]#这里可以是 self.path_file.setText(self.filename) 打印(文件名) 返回文件名“\”您可以删除它。 点击工作时的def(自我): 如果len(self.w_pz.text())小于1: messagebox.showinfo(“信息”,“请把东西放进去”) elif len(self.w_pn.text())

Python ) self.filename=fname[0]#这里可以是 self.path_file.setText(self.filename) 打印(文件名) 返回文件名“\”您可以删除它。 点击工作时的def(自我): 如果len(self.w_pz.text())小于1: messagebox.showinfo(“信息”,“请把东西放进去”) elif len(self.w_pn.text()),python,function,pyqt,parameter-passing,Python,Function,Pyqt,Parameter Passing,也就是说,不需要在两个函数之间传递valiable。 首先,您要创建self.filename对象。当你得到filename时,将它设置为self.filename。最后,你在方法中使用它。我认为这是解决这个问题的最好办法 在这种情况下,它将比Signal&Slot更容易。请将您的代码简化为[最小。完整且可验证](www.stackoverflow.com/help/mcve)示例,不要只发布部分代码,因为它没有任何意义。谢谢我编辑了这篇文章。你现在能帮我吗?我想你应该用self调用你的函数。在

也就是说,不需要在两个函数之间传递valiable。 首先,您要创建
self.filename
对象。当你得到
filename
时,将它设置为
self.filename
。最后,你在方法中使用它。我认为这是解决这个问题的最好办法


在这种情况下,它将比Signal&Slot更容易。

请将您的代码简化为[最小。完整且可验证](www.stackoverflow.com/help/mcve)示例,不要只发布部分代码,因为它没有任何意义。谢谢我编辑了这篇文章。你现在能帮我吗?我想你应该用self调用你的函数。在点击获取文件()时,不要把文件名作为参数传递(因为点击获取文件时你的函数不带参数)。
Process finished with exit code -1073740791 (0xC0000409)
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import *
from PyQt5.QtWidgets import QGridLayout, QWidget, QDesktopWidget
from tkinter import messagebox
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QMainWindow, QPushButton, QAction, QMessageBox
from PyQt5.QtWidgets import QCalendarWidget, QFontDialog, QColorDialog, QTextEdit, QFileDialog
from PyQt5.QtWidgets import QCheckBox, QProgressBar, QComboBox, QLabel, QStyleFactory, QLineEdit, QInputDialog
from PyQt5.QtWidgets import QTabWidget
from file_to_text2 import convert_file_to_txt2
from excel_function import work_file_with_excel




OUTPUT_FILENAME = 'test.txt'


class main_window(QTabWidget):
    def __init__(self, parent=None):
        super(main_window, self).__init__(parent)


        self.setGeometry(50,50, 1078, 541)
        self.setWindowTitle("Lea\'s Program")

        qtRectangle = self.frameGeometry()
        centerPoint = QDesktopWidget().availableGeometry().center()
        qtRectangle.moveCenter(centerPoint)
        self.move(qtRectangle.topLeft())


        self.centralWidget = QtWidgets.QWidget()
        self.tabWidget = QtWidgets.QTabWidget(self.centralWidget)
        self.tabWidget.setGeometry(QtCore.QRect(10, 10, 1200, 1000))
        self.tabWidget.setLayoutDirection(QtCore.Qt.LeftToRight)
        self.tabWidget.setTabPosition(QtWidgets.QTabWidget.West)


        self.tab_v1 = QtWidgets.QWidget()
        self.addTab(self.tab_v1, "Read")


        self.openFile = QPushButton("Get file", self.tab_v1)
        self.openFile.setGeometry(QtCore.QRect(700, 15, 200, 30))
        self.openFile.clicked.connect(self.on_click_getfile)


        self.path_file = QLabel("",self.tab_v1)
        self.path_file.setGeometry(QtCore.QRect(200, 15, 350, 30))

        self.groupbox = QGroupBox('Informationen', self.tab_v1)
        self.groupbox.setGeometry(QtCore.QRect(15, 100, 1000, 600))

        self.w_pz = QLineEdit(self.groupbox)
        self.w_pz.setGeometry(QtCore.QRect(212, 150, 250, 22))

        self.w_pn = QLineEdit(self.groupbox)
        self.w_pn.setGeometry(QtCore.QRect(212, 200, 250, 22))

        self.work_file = QtWidgets.QPushButton("Search", self.tab_v1)
        self.work_file.setGeometry(QtCore.QRect(700, 250, 150, 30))
        self.work_file.clicked.connect(self.on_click_work)

    def on_click_getfile(self):
        fname = QFileDialog.getOpenFileName(self,
                                            'Open file',
                                            'c:\\',
                                            'Alle LV-Check-Datein,(*.txt *.docx *.xml *.x81 *.pdf)'
                                            #'Alle Datein (*.*)'
                                            )
        filename = fname[0]
        self.path_file.setText(filename)
        print (filename)

        return filename # with this i want to pass the filename to on_click_work

    def on_click_work(self):
        if len (self.w_pz.text()) < 1:
            messagebox.showinfo("Information", "Please  put something in")
        elif len (self.w_pn.text()) < 1:
            messagebox.showinfo("Information", "Please  put something in")
        else:
            input_lv =([self.w_pz.text(),self.w_pn.text()])
            print (input_lv)

            filename = on_click_getfile(filename) ##this should get the filename from the on_click_getfile function
            print (filename)
            convert_file_to_txt2(filename,input_lv, output_filename=OUTPUT_FILENAME) # this should start running convertig different filetypes depending on the filename, which was put in at teh on_click_getfile function
            work_file_with_excel(OUTPUT_FILENAME) # this should get the outputfile from convert_file_to_txt2 and run a search

def main():
    app = QApplication(sys.argv)
    ex = main_window()
    ex.show()
    sys.exit(app.exec_())


if __name__ == '__main__':
    main()
-omitting-
self.current_filename = ""#here
def on_click_getfile(self):
        fname = QFileDialog.getOpenFileName(self,
                                            'Open file',
                                            'c:\\',
                                            'Alle LV-Check-Datein,(*.txt *.docx *.xml *.x81 *.pdf)'
                                            #'Alle Datein (*.*)'
                                            )
        self.filename = fname[0]#here this can be
        self.path_file.setText(self.filename)
        print (filename)

        return filename`# you may delete it.




def on_click_work(self):
    if len (self.w_pz.text()) < 1:
        messagebox.showinfo("Information", "Please  put something in")
    elif len (self.w_pn.text()) < 1:
        messagebox.showinfo("Information", "Please  put something in")
    else:
        input_lv =([self.w_pz.text(),self.w_pn.text()])
        print (input_lv)

        #filename = on_click_getfile(filename) ##this should get the filename from the on_click_getfile function
        #print (filename)
        convert_file_to_txt2(self.filename#here,input_lv, output_filename=OUTPUT_FILENAME) # this should start running convertig different filetypes depending on the filename, which was put in at teh on_click_getfile function
        work_file_with_excel(OUTPUT_FILENAME) # this should get the outputfile from convert_file_to_txt2 and run a search