Python Forum
browse item and assign file to variable PYSIDE
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
browse item and assign file to variable PYSIDE
#1
hello,

I would like to parse a file using a GUI dialog window rather than writing the path directly; so I am using pyside to implement the window. I got the code to browse a file and import it's content as a text string; what I would need is instead to assign the file (or actually its path) I have chosen with the window to an object so that I can use another function to parse the file more properly. 

for example, I would need to select the file with the window, then assign the path, let's say,

> /home/gigiux/Documents/myFile.raw

to the variable 'x' and then parse with, for instance, 

> parseFun(x, type=raw)

How should I define the function? So far the code I wrote for browsing the file is:

    def openFile(self):
     self.fileName, self.filterName = QFileDialog.getOpenFileName(self)
     self.textEdit.setText(open(self.fileName).read())

thanks
Reply
#2
(Apr-23-2017, 01:11 PM)Gigux Wrote: How should I define the function?
     self.textEdit.setText(open(self.fileName).read())

If you're going to put the contents of the file in the gui that's fine, but you still should close the file after reading it.
Reply
#3
Hmm, and I would I do that? and more importantly, how do I do the assignment? Tx
Reply
#4
with open(self.fileName) as file:
   self.textEdit.setText(file.read())
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PySide / PyQt] Offset two images with keyboard increments carecavoador 1 992 Sep-09-2023, 12:53 PM
Last Post: deanhystad
Question Rows and colums list. PySide 6 britesc 2 900 May-31-2023, 09:00 PM
Last Post: deanhystad
  Drawing in PySide Leo_Red 3 2,823 Jun-26-2021, 09:30 AM
Last Post: Axel_Erfurt
  How to in PySide/PyQt, zooming in and out UI Vladlen 0 2,911 Feb-13-2019, 02:11 PM
Last Post: Vladlen
  (pyQt/pySide)setStyleSheet(border…) makes QPushButton not clickable in Maya vladlenPy 0 4,730 Apr-15-2018, 12:41 PM
Last Post: vladlenPy
  Browse/Navigate Webpages ian 2 3,320 Jul-19-2017, 09:02 PM
Last Post: nilamo
  set font from dialog box pyside python Gigux 1 3,596 May-08-2017, 12:25 AM
Last Post: Joseph_f2
  set default font main window pyside Gigux 0 3,488 Apr-23-2017, 01:13 PM
Last Post: Gigux

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020