'PyQT5 TypeError: startfile: filepath should be string, bytes or os.PathLike, not Ui_MainWindow
I'm trying to build an app here. I used QT Designer to build the main window (Ui_MainWindow) with buttons. I import this to a new file where I can structure the code a bit better.
Anyhow, I keep getting the error "TypeError: startfile: filepath should be string, bytes or os.PathLike, not Ui_MainWindow" whenever I try to get the filename via QFileDialog. This filename is used in the GetData -method to produce a dataframe. I'm sure I'm doing something horribly wrong here in my code. I understood that you can call methods within other methods
So I will have 3 buttons:
- Open folder (which gets the filename)
- Update data (which is connected to UpdateData method. This method updates the data as I want)
- Calculate (a method that calculates something based on the output from updateData -method.)
So I am trying to get an output from step 1 to use as input in step 2, to get an output which then would be used as input in step 3 and then - voilá.
What am I doing wrong?
from myQTDesignerGUIfile import Ui_MainWindow
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import (QApplication, QMainWindow, QPushButton, QLabel, QFileDialog, QMessageBox)
from PyQt5.QtCore import pyqtSlot, QFileInfo
class MyApp(QtWidgets.QMainWindow, Ui_MainWindow):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
#Build instance of setpUI in Ui_MainWindow -class
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
def GetFileName(self):
FileFilter = 'File (*.xlsx *.xlsm *.csv)'
FileName = QFileDialog.getOpenFileName(parent = self,
caption="Select File",
directory = 'Some Path',
filter = FileFilter)[0]
path = str(FileName)
if path:
print(path)
return path
def GetData(self):
path = self.GetFileName
return pd.read_csv(path)
def UpdateData(self):
## get data using the GetData -method
df = self.GetData()
## code to modify data is written here
return final_mod_data
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
w = MyApp()
w.show()
app.exec()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
