PyQt4 example working from IDLE, but not when executed from npp

試著忘記壹切 提交于 2019-12-12 03:52:39

问题


I am running a very basic example in PyQt4. It is shown below. I was struggling with the Enthought Canopy installation, struggling with the cygwin Python implementation, and finally just installed Python 2.7, Numpy 1.7.1, MatPlotLib 1.2.0 one at a time.

When I execute the example from IDLE, it works fine. Although when I try to execute it from Notepad++ using nppExec, the console window just hangs. I do not see a little empty window pop up anywhere, nor am I given any error codes.

  • I tried interactive mode and non-interactive mode from nppExec (-i)
    • My nppExec command is python "$(FULL_CURRENT_PATH)"
  • I tried pulling the guts of tho code out of the function definition and running it by itself, same thing.

.

  • Python 2.7.4
  • notepad++ 6.3.2
  • PyQt4 4.10.1

    import sys
    from PyQt4 import QtGui
    
    
    def main():
    
        app = QtGui.QApplication(sys.argv)
    
        w = QtGui.QWidget()
        w.resize(250, 150)
        w.move(300, 300)
        w.setWindowTitle('Brian')
        w.show()
    
    sys.exit(app.exec_())
    
    
    if __name__ == '__main__':
        main()
    

回答1:


In NppExec, use the command

CMD /C python -u "$(FULL_CURRENT_PATH)"

instead of

python "$(FULL_CURRENT_PATH)"



回答2:


I had/have the same issue. Using w.showMaximized() instead of w.show() solved for me the problem of not showing the window in Notepad++. Subsequent opened widgets can be opened with w.show().

However, your code did not work for me, I got a Python traceback. Instead I used (with PySide):

import sys
from PySide import QtGui

app = QtGui.QApplication(sys.argv)

def main():

    w = QtGui.QWidget()
    w.resize(250, 150)
    w.move(300, 300)
    w.setWindowTitle('Brian')
    w.showMaximized()
    app.exec_()


if __name__ == '__main__':
    main()

And, as a work-around, just add something like w.resize(width, height) after you called w.showMaximized() to resize the window to your target size.



来源:https://stackoverflow.com/questions/16388629/pyqt4-example-working-from-idle-but-not-when-executed-from-npp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!