import sys
from PyQt4 import QtGui, QtCore
class Example(QtGui.QWidget):
def __init__(self, items=None):
super(Example, self).__init__()
self.items = items or {'India':['New Delhi', 'Bangalore']}
self.initUI()
def initUI(self):
self.combo = QtGui.QComboBox(self)
self.cbBox = QtGui.QComboBox(self)
self.combo.addItems(self.items.keys())
self.cbBox.addItems(self.items[str(self.combo.currentText())])
self.combo.move(50, 50)
self.cbBox.move(50,80)
self.combo.currentIndexChanged.connect(self.onActivated)
self.setGeometry(300, 300, 300, 200)
self.setWindowTitle('Learning by practice')
self.show()
def onActivated(self):
self.cbBox.clear()
self.cbBox.addItems(self.items[str(self.combo.currentText())])
def main():
app = QtGui.QApplication(sys.argv)
items = sys.argv[1:]
ex = Example(items)
sys.exit(app.exec_())
if __name__ == '__main__':
main()
the above code gives error if i pass this dictionary {'India':['New Delhi', 'Bangalore'], 'Canada': ['Toronto','Vancouver']} from the command line.