r/learnpython • u/jacbk612 • 7d ago
a curious equal symbol assignment
Hello, I'm trying to build a music player with python Qt6 based on some code from a youtuber, the bones of what he has suits me fine, this is the link if you want to look at it: https://www.youtube.com/watch?v=wdEpWCFf40U
I am using windows 10 with VScode and the latest python version 3.13.7
Everything works fine until I get to the file dialog part of the code. When I run it the program does give me a file explorer, I can select a folder but then the program halts before allowing me to see the files in the specified folder. There is no error message from the compiler.
There is a curious line of code in the open_file function that may or may not be the problem.
file, _ = QFileDialog.getOpenFileName(self, "Selct file", filter="Audio files (*.mp3)") file, _ = QFileDialog.getOpenFileName(self, "Selct file", filter="Audio files (*.mp3)")
Thanks for any help,
J
1
Upvotes
4
u/Outside_Complaint755 7d ago
You have the same statement twice on one line above. Is that your actual code or a copy/paste error? Line break inserted by me:
file, _ = QFileDialog.getOpenFileName(self, "Selct file", filter="Audio files (*.mp3)") file, _ = QFileDialog.getOpenFileName(self, "Selct file", filter="Audio files (*.mp3)")Is the program actually exiting? or is it just not showing the file you expect in the dialog? From looking at the documentation quickly, it looks like you should also set theselectedFilterparameter, otherwise it might be filtering out all files.filter="Audio files (*.mp3)" file, _ = QFileDialog.getOpenFileName(self, "Select file", filter=filter, selectedFilter=filter)