[PyQt] Two questions about PyQt

tiob lew lewtiob at hotmail.com
Wed Nov 25 06:19:48 GMT 2009


I am a newbie to Python and have two questions using python to design UI based 
PyQT4.6. 

The source code is 
=========================================== 
#!/usr/bin/python 
#MyUI.py 

import sys 
import random 
from PyQt4 import QtCore, QtGui 


class MyUI(QtGui.QWidget): 
    def __init__(self, parent=None): 
        QtGui.QWidget.__init__(self, parent) 
        self.setWindowTitle('My UI') 

        cb1 = QtGui.QCheckBox('MyCheckBox1', self) 
        cb2 = QtGui.QCheckBox('MyCheckBox2', self) 

        bg = QtGui.QButtonGroup(parent) 
        
        bg.setExclusive(1) 
        bg.addButton(cb1) 
        bg.addButton(cb2) 
        
        hbox = QtGui.QHBoxLayout() 
        hbox.addStretch(1) 
        hbox.addWidget(cb1) 
        hbox.addWidget(cb2) 
        self.setLayout(hbox) 
        self.resize(900, 600) 

        lb1 = QtGui.QLabel('Name') 
        lb2 = QtGui.QLabel('Age') 
        lb3 = QtGui.QLabel('Address') 

        tf1 = QtGui.QLineEdit() 
        tf2 = QtGui.QLineEdit() 
        tf3 = QtGui.QLineEdit() 
                
        hbox.addWidget(lb1) 
        hbox.addWidget(tf1) 
        hbox.addWidget(lb2) 
        hbox.addWidget(tf2) 
        hbox.addWidget(lb3) 
        hbox.addWidget(tf3) 
        
        tf1.setText('Jone') 
        tf2.setText('28') 
        tf3.setText('London')         
    
        update = QtGui.QPushButton('update') 
        hbox.addWidget(update) 
        self.connect(update, QtCore.SIGNAL('clicked()'), 
             self, QtCore.SLOT('update_info(self)')) 
                
    def update_info(self): 
        tf1.setText('Alice') 
        tf2.setText('18') 
        tf3.setText('New York') 
    
app = QtGui.QApplication(sys.argv) 
ui = MyUI() 
ui.show() 
sys.exit(app.exec_()) 


============================================ 

I want to implement two functions in this piece of code. 
1) implement the exclusive checkbox in a group of checkboxes. In another word, 
only one of CheckBox1 and Checkbox2 could be checked at any time. 

2) After clicking "update" button, the information should be updated as 
Name ----> Alice 
Age -----> 18 
Address---> New York 


How should the code be modified to implement this two functionalities? 

Many thanks. 
 		 	   		  
_________________________________________________________________
Hotmail: Trusted email with powerful SPAM protection.
http://clk.atdmt.com/GBL/go/177141665/direct/01/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20091125/990d8f1c/attachment-0001.html


More information about the PyQt mailing list