Я сделал приложение для дестопа. С помощью одной кнопки (button_on_click_getfile) вы можете выбрать файл.С другой кнопкой (button_on_click_work) вы должны работать с файлом.Мне нужно немного информации от пользователя перед обработкой файла, поэтому мне нужно передать имя файла из файла button_on_click_getfile в button_on_click_work.
Как мне передать имя файла.Мой код работает, но при нажатии button_on_click_work возвращает следующее:
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()