954,510 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How do I load python QT module into my python 3.2 or any python

Please I downloaded the latest version of python QT but I've been unable to use because i don't know how, help from the experts in the house.

Thanks in advance

e-papa
Posting Pro in Training
465 posts since Mar 2011
Reputation Points: 23
Solved Threads: 4
 
Ene Uran
Posting Virtuoso
1,723 posts since Aug 2005
Reputation Points: 625
Solved Threads: 213
 

Will check and get back to you.

e-papa
Posting Pro in Training
465 posts since Mar 2011
Reputation Points: 23
Solved Threads: 4
 

I assume you are using the Windows OS and Python 3.2, simply do this ...

For PyQT download and run the Windows 32 bit self-extracting installer
PyQt-Py3.2-x86-gpl-4.8.3-1.exe
from http://www.riverbankcomputing.co.uk/.../pyqt/download

Py3.2 indicates that this the installer for Python 3.2, there are installers for other versions of Python too.

You can copy, click on (Toggle Plain Text) first, and paste the typical PyQT code below and run it from an IDE like IDLE that comes with your Python installation ...

# use PyQT to draw a simple vertical bar chart
# tested with PyQT4.8 and Python3.2

from PyQt4.QtCore import *
from PyQt4.QtGui import *

class BarChart(QWidget):
    def __init__(self, data, parent=None):
        # create the window (will be instance self)
        QWidget.__init__(self, parent)
        # setGeometry(x_pos, y_pos, width, height)
        self.setGeometry(300, 300, 360, 320)
        self.setWindowTitle('Simple Bar Chart')
        self.data = data

    def paintEvent(self, event):
        painter = QPainter()
        painter.begin(self)
        
        # set color and width of line drawing pen
        painter.setPen(QPen(Qt.black, 2))
        
        # drawLine(x1, y1, x2, y2) from point (x1,y1) to (x2,y2)
        # draw the baseline
        painter.drawLine(20, 280, 340, 280)        

        # set up color and width of the bars
        width = 20
        painter.setPen(QPen(Qt.red, width))
        delta = width + 5
        x = 30
        for y in self.data:
            # correct for width
            y1 = 280 - width/2
            y2 = y1 - y + width/2
            # draw each bar
            painter.drawLine(x, y1, x, y2)
            # add values to the top of each bar
            s = str(y)
            painter.drawText(x-8, y2-15, s)
            x += delta        

        painter.end()


# data to be graphed
data = [30, 45, 80, 150, 220, 180, 110, 75, 50, 35, 20, 10]
app = QApplication([])
bc = BarChart(data)
bc.show()
app.exec_()


For some helpful hints on IDLE see: http://www.daniweb.com/software-development/python/threads/20774/104834#post104834

vegaseat
DaniWeb's Hypocrite
Moderator
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
 

Thanks a million.

e-papa
Posting Pro in Training
465 posts since Mar 2011
Reputation Points: 23
Solved Threads: 4
 

Tested with PySide, worked by only changing PyQT4 to PySide.

It did not like IDLE though, giving nothing more serious than crash reports, but directly running from command line was OK.

pyTony
pyMod
Moderator
5,359 posts since Apr 2010
Reputation Points: 782
Solved Threads: 852
 

Okay but what is pyside.

e-papa
Posting Pro in Training
465 posts since Mar 2011
Reputation Points: 23
Solved Threads: 4
 

It is alternative for PyQT which has no limitations for commercial use (LGPL), I sent one announcement resently to Python forum, when I realised it came out. PyQT has two licence models GPL, which is free for non-commercial use, and other by payment for commercial development.
LGPL: Pyside bindings for QT released!

pyTony
pyMod
Moderator
5,359 posts since Apr 2010
Reputation Points: 782
Solved Threads: 852
 

Okay will check it out.

e-papa
Posting Pro in Training
465 posts since Mar 2011
Reputation Points: 23
Solved Threads: 4
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: