Reputation: 607
I am new to Python and PyQt. This function is not within a class, and is called by another function that is not self referencing. (I'm not sure if that's what you call it. What I mean is, none of the functions are of the type function_name(self)
)
def openFileDialog():
filename = QtGui.QFileDialog.getOpenFileName(self, "Open File", "/home/username/Pictures")
print(filename)
What can I pass instead of self
? I have tried Dialog
, none
, parent=none
, but neither of those work.
Upvotes: 1
Views: 1022
Reputation: 37599
The parent
argument is just so the QFileDialog
is correctly parented to a widget. There are many reasons why you would want dialogs and windows to be correctly parented to each other.
If you don't care about any of these things, you could just pass in None
.
filename = QtGui.QFileDialog.getOpenFileName(None, "Open File", "/home/username/Pictures")
Or, to be a little more versatile, give your function an optional parent
argument
def openFileDialog(parent=None):
filename = QtGui.QFileDialog.getOpenFileName(parent, "Open File", "/home/username/Pictures")
print(filename)
Upvotes: 2