Solved Include a button to open .tif image
-
Hello,
I use this code: https://github.com/kklmn/OrthoView/blob/master/OrthoView.py
what changes should I do, so that I can import the image file via putting a button and choosing the file. Because now I use the image file by putting the path into the code. I need to open the file through a button in order to choose different images when I run the code... I am reading this code: https://www.tutorialspoint.com/pyqt/pyqt_qfiledialog_widget.htm in order to understand the basics... Thank you
-
The solution already is on your linked site:
Use
QFileDialog
to pick the image and trigger the dialog with your button.self.btn = QPushButton("QFileDialog static method demo") self.btn.clicked.connect(self.getfile) def getfile(self): fname = QFileDialog.getOpenFileName(self, 'Open file', 'C:\\',"Image files (*.jpg *.gif)") // DO SOMETHING WITH YOUR IMG
-
I added them, but I do no see any button to open and choose file
-
@john_hobbyist
Hi
well did you add the button to your main screen ?
To a layout most likely.Just creating the button wont show it anywhere :)
-
If you mean this:
layout.addWidget(self.btn)
I have added it.
-
@john_hobbyist
Yep that seems ok. -
But I cannot see the button to open file...
update: Ok I fixed it! Thanks a lot for your time...This error:
NameError: name 'QFileDialog' is not defined
means that I need to import something from PyQt5 ?
Answer: Yes :-)