Reply
Thread Tools
El Amir's Avatar
Posts: 487 | Thanked: 152 times | Joined on Aug 2007 @ London, UK
#1
Hey,

This is a problem that I'm trying to solve for my App called "Vuvuzela".

I'm trying to find a way to load a specific picture at the click of a button.

I can load the "Vuvuzela.png" image just fine when no interaction is involved but as soon as I try to use the button, the image does not refresh to the "Green-vuvu.png"

The - Print 'Green' - is just there to make sure my slots work well.

Any input would be greatly appreciated!


Code:
#!/usr/bin/env python

import sys, pygame, time
import pygame.mixer 
from PyQt4 import QtCore
from PyQt4 import QtGui
from pygame.locals import *
   
                              
pygame.mixer.init() 
pygame.init()

class Vuvu(QtGui.QWidget):
    def __init__(self, parent=None):
        
        QtGui.QWidget.__init__(self, parent)
        
        self.color = QtGui.QColor(255, 0, 0) 
        
        self.setGeometry(300, 300, 800, 480)
        self.setWindowTitle('Vuvuzela')
        
        vuvupic = QtGui.QPixmap("images/Vuvuzela.png")
        label = QtGui.QLabel(self)
        label.setPixmap(vuvupic)
        label.move(103, 100)
        
        self.greenvuvu = QtGui.QPushButton('Green Vuvu', self)
        #self.red.setCheckable(True)
        self.greenvuvu.setGeometry(0, 0, 70, 70)
        self.connect(self.greenvuvu, QtCore.SIGNAL('clicked()'), self.setVuvuGreen)
        
        
    def setVuvuGreen(self):
        vuvupicgreen = QtGui.QPixmap("images/Vuvu-Green.png")
        label2 = QtGui.QLabel(self)
        label2.setPixmap(vuvupicgreen)
        label2.move(103, 400)
        print "Green"

        
app = QtGui.QApplication(sys.argv)
vv = Vuvu()
vv.show()
app.exec_()
__________________
Follow me on twitter HERE!

Applications I've made:
- Vuvuzela
- LTM: London Tube Map

Last edited by El Amir; 2010-06-29 at 10:06.
 
Posts: 75 | Thanked: 9 times | Joined on Dec 2009 @ Verona, Italy
#2
Originally Posted by El Amir View Post
Hey,

This is a problem that I'm trying to solve for my App called "Vuvuzela".

I'm trying to find a way to load a specific picture at the click of a button.

I can load the "Vuvuzela.png" image just fine when no interaction is involved but as soon as I try to use the button, the image does not refresh to the "Green-vuvu.png"

The - Print 'Green' - is just there to make sure my slots work well.

Any input would be greatly appreciated!


Code:
#!/usr/bin/env python

import sys, pygame, time
import pygame.mixer 
from PyQt4 import QtCore
from PyQt4 import QtGui
from pygame.locals import *
   
                              
pygame.mixer.init() 
pygame.init()

class Vuvu(QtGui.QWidget):
    def __init__(self, parent=None):
        
        QtGui.QWidget.__init__(self, parent)
        
        self.color = QtGui.QColor(255, 0, 0) 
        
        self.setGeometry(300, 300, 800, 480)
        self.setWindowTitle('Vuvuzela')
        
        vuvupic = QtGui.QPixmap("images/Vuvuzela.png")
        label = QtGui.QLabel(self)
        label.setPixmap(vuvupic)
        label.move(103, 100)
        
        self.greenvuvu = QtGui.QPushButton('Green Vuvu', self)
        #self.red.setCheckable(True)
        self.greenvuvu.setGeometry(0, 0, 70, 70)
        self.connect(self.greenvuvu, QtCore.SIGNAL('clicked()'), self.setVuvuGreen)
        
        
    def setVuvuGreen(self):
        vuvupicgreen = QtGui.QPixmap("images/Vuvu-Green.png")
        label2 = QtGui.QLabel(self)
        label2.setPixmap(vuvupicgreen)
        label2.move(103, 400)
        print "Green"

        
app = QtGui.QApplication(sys.argv)
vv = Vuvu()
vv.show()
app.exec_()
If i'm not wrong, there is a function to refresh or update the gui.....
 
Posts: 75 | Thanked: 9 times | Joined on Dec 2009 @ Verona, Italy
#3
Or, take a look here: http://www.commandprompt.com/community/pyqt/c6351

Maybe you need setStyle?
 
Posts: 3,617 | Thanked: 2,412 times | Joined on Nov 2009 @ Cambridge, UK
#4
That looks rather messy - you're creating a new label & trying to superimpose it over the original one. I'd suggest instead saving the original label object (self.imageLabel = label) and then in the function just replacing the image used ( self.imageLabel.setPixmap(vuvupicgreen) )
 

The Following 2 Users Say Thank You to Rob1n For This Useful Post:
El Amir's Avatar
Posts: 487 | Thanked: 152 times | Joined on Aug 2007 @ London, UK
#5
Originally Posted by maurelio79 View Post
If i'm not wrong, there is a function to refresh or update the gui.....
Looked into that but not really what I needed for this one. Thanks anyway!

Originally Posted by maurelio79 View Post
Or, take a look here: http://www.commandprompt.com/community/pyqt/c6351

Maybe you need setStyle?
Will do for the next features I will implement! Cheers


Originally Posted by Rob1n View Post
That looks rather messy - you're creating a new label & trying to superimpose it over the original one. I'd suggest instead saving the original label object (self.imageLabel = label) and then in the function just replacing the image used ( self.imageLabel.setPixmap(vuvupicgreen) )
Spot on! All I needed to do was to comment out the new "label creation" and the" move" function.

Thanks alot!
__________________
Follow me on twitter HERE!

Applications I've made:
- Vuvuzela
- LTM: London Tube Map
 
Reply


 
Forum Jump


All times are GMT. The time now is 18:12.