|
2010-06-29
, 12:40
|
Posts: 75 |
Thanked: 9 times |
Joined on Dec 2009
@ Verona, Italy
|
#2
|
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_()
|
2010-06-29
, 12:46
|
Posts: 75 |
Thanked: 9 times |
Joined on Dec 2009
@ Verona, Italy
|
#3
|
|
2010-06-29
, 13:08
|
Posts: 3,617 |
Thanked: 2,412 times |
Joined on Nov 2009
@ Cambridge, UK
|
#4
|
The Following 2 Users Say Thank You to Rob1n For This Useful Post: | ||
|
2010-06-30
, 05:32
|
|
Posts: 487 |
Thanked: 152 times |
Joined on Aug 2007
@ London, UK
|
#5
|
If i'm not wrong, there is a function to refresh or update the gui.....
Or, take a look here: http://www.commandprompt.com/community/pyqt/c6351
Maybe you need setStyle?
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) )
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!
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.