LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-04-2016, 10:26 AM   #1
iFunction
Member
 
Registered: Nov 2015
Posts: 248

Rep: Reputation: Disabled
python PyQt4 scripts won't run


Hi there,

First off, apologies if this is in the wrong place, but I'm at a loss right now.

I'm trying to learn how to do gui in python, and I am having trouble just getting a window on the screen using this script I found this on this internet. I am fairly sure it is right as it corresponds very well to another thing I was trying, but on execution, nothing happens, the prompt doesn't return any error, just nothing happens, I have left in all credits, as I have copied it directly and just want to get it working:
Code:
#!/usr/bin/python
# -*- coding: utf-8 -*-

"""
ZetCode PyQt4 tutorial 

In this example, we create a simple
window in PyQt4.

author: Jan Bodnar
website: zetcode.com 
last edited: October 2011
"""

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('Simple')
    w.show()
    
    sys.exit(app.exec_())


if __name__ == '__main__':
    main()
Please can someone enlighten me as to why I am not getting a window on the screen using this code, Yet when I can with this:
Code:
import sys
from PyQt4 import QtGui
app = QtGui.QApplication(sys.argv)
window = QtGui.QWidget()
window.show()
In fact, I just tried putting this in a script and it doesn't work as a script either, so I am doing something very wrong, as it works when you just plug it straight into the shell. However I can print text from a script, that works. I'm at a bit of a loss now, as I must have the right libraries installed to run this, and I can run other python scripts. I am using a Raspberry Pi3 by the way.

Any help on this would be very much appreciated.

IFunction
 
Old 04-04-2016, 11:40 AM   #2
iFunction
Member
 
Registered: Nov 2015
Posts: 248

Original Poster
Rep: Reputation: Disabled
I have made something of a breakthrough, in that a very simple version of this works without any of the main function by adding:
Code:
app.exec_()
which apparently is required for linux, but I can't get it to work in the script here. any ideas?
 
Old 04-04-2016, 12:57 PM   #3
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
No idea what's wrong but FYI your original code works fine on my machine:
Code:
>>> import sys
>>> from PyQt4.QtCore import QT_VERSION_STR
>>> from PyQt4.Qt import PYQT_VERSION_STR
>>> print sys.version
2.7.11+ (default, Mar 23 2016, 11:35:56) 
[GCC 5.3.1 20160316]
>>> print QT_VERSION_STR
4.8.7
>>> print PYQT_VERSION_STR
4.11.4
 
Old 04-06-2016, 05:24 AM   #4
iFunction
Member
 
Registered: Nov 2015
Posts: 248

Original Poster
Rep: Reputation: Disabled
Ok, I copied what you did here, and get the following:
Code:
>>> print sys.version
2.7.9 (default, Mar 8 2015, 00:52:26)
[GCC 4.9.2]
>>> print QT_VERSION_STR
4.8.6
>>> print PYQT_VERSION_STR
4.11.2
This is after a full update on a fresh Raspbian_Jessie install update and upgrade, so I am assuming this is as updated as is supported for the Raspberry Pi.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Script to run all the python scripts from particular directory mandar.nandale Linux - General 4 05-08-2012 01:29 AM
Is it possible to use python scripts to run a dzen2 status bar? daweefolk Linux - General 0 02-08-2011 03:38 PM
Maemo PyQt4+Gstreamer Segfault (Python) Snark1994 Linux - Mobile 0 01-13-2011 04:13 PM
How to run shell scripts wrapped in Python. narnie Programming 20 07-15-2010 12:41 AM
Python/PyQt4 - Newbie Structure question ocularb0b Programming 0 01-28-2008 09:42 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration