Python - How do I get my GUI to display in Spyder
Clearing this one up, as the answer was posted in the comments by Patrick Artner.
Simply adding () after w.show solved the problem.
Related videos on Youtube
![Steven Goddard](https://i.stack.imgur.com/q1KOc.jpg?s=256&g=1)
Steven Goddard
Updated on June 04, 2022Comments
-
Steven Goddard about 2 years
I'm new to creating GUI's in Python and can't seem to get over the first hurdle. I'm using Anaconda - Spyder and I normally run all (mainly mathematical) code through this (and the IPython console?).
My issue is that when I run the code below I'm expecting it to display a simple blank window but nothing happens.
Is Spyder/IPython not the best way to do this or is there an issue with my code?
I've tried using the command prompt by typing "python TestScript.py" whilst in the correct directory but I get an error saying 'Python is not recognised as a internal or external command'. Do I need to set up cmd to use Anaconda?
import sys from PyQt5.QtWidgets import QApplication, QWidget if __name__ == '__main__': app = QApplication(sys.argv) w = QWidget() w.resize(250,150) w.move(30,30) w.setWindowTitle('Simple Window') w.show sys.exit(app.exec_())
-
Patrick Artner over 6 yearsadding
()
afterw.show
might help -
Patrick Artner over 6 yearsWelcom to SO. Great first post - clear and concise. You should have googled/SO-Searched for QApplication before asking, you would have seen lots of results (f.e. stackoverflow.com/questions/17601896/… ) with running code - and compared it to yours which would have made the error obvious. :)
-
Steven Goddard over 6 yearsThanks Patrick after all that it was a simple case of two brackets! I did have a good go at searching for an answer but I was thinking it was more to do with my set up of Spyder/settings etc..!
-