python - How to take input from ComboBox in PyQt4 -


i have created combobox in pyqt4. combobox have 5 options , user needs select 1 option among , click submit button. have tried define function called printing action used after user clicks submit button

def home(self):      self.lbl = qtgui.qlabel('types of analysis', self)     self.lbl.setfont(qtgui.qfont('sansserif', 15))     btn = qtgui.qpushbutton('submit', self)     btn.move(200, 200)     cb = qtgui.qcombobox(self)     btn = qtgui.qpushbutton('submit', self)     cb.additem('sentiment analysis')     cb.additem('data cleansing')     cb.additem('genomics')     cb.additem('integration')     cb.additem('visualization')     cb.move(200,100)     cb.resize(150,40)     qtgui.qapplication.setstyle(qtgui.qstylefactory.create('cleanlooks'))     cb.activated[str].connect(self.onactivate)     btn.clicked.connect(self.printingaction)     self.show()  def printingaction(self):     print(t) 

can me in understanding how take input after user has selected 1 among given options , presses submit button

here's example print combobox's current text , index:

import sys pyqt4 import qtgui, qtcore  class mywindow(qtgui.qwidget):     def __init__(self, parent = none):         super(mywindow, self).__init__(parent)          # create controls         self.lbl = qtgui.qlabel('types of analysis', self)         self.lbl.setfont(qtgui.qfont('sansserif', 15) )         self.cb = qtgui.qcombobox(self)         self.cb.additems(['sentiment analysis', 'data cleansing', 'genomics', 'integration', 'visualization'])         self.btn = qtgui.qpushbutton('submit', self)         self.btn.clicked.connect(self.printingaction)          # create layout         mainlayout = qtgui.qvboxlayout()         mainlayout.addwidget(self.lbl)         mainlayout.addwidget(self.cb)         mainlayout.addwidget(self.btn)         self.setlayout(mainlayout)          self.show()      def printingaction(self):         print 'current item: {0}'.format( self.cb.currentindex() ) # combobox's index         print 'current index: {0}'.format( self.cb.currenttext() ) # combobox's text  if __name__ == '__main__':     app = qtgui.qapplication(sys.argv)     win = mywindow()     sys.exit( app.exec_() ) 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -