반응형

/*********************************************************************************************************
-- Title : [PyQt4] Combobox 구현

-- Reference : pythonspot.com
-- Key word : 파이썬 python pyqt qt qt4 gui 콤보박스 콤보 박스 combo combobox

*********************************************************************************************************/

# -*- coding: utf-8 -*-

import sys
from PyQt4.QtCore import pyqtSlot
from PyQt4.QtGui import *

# ------------------------------------------
# -- Create window
# ------------------------------------------
myApp = QApplication(sys.argv) # Create an PyQT4 application object.
w = QWidget() # The QWidget widget is the base class
w.setWindowTitle('Add Combobox')
w.resize(400, 200)

# ------------------------------------------
# -- Create textbox
# ------------------------------------------
myTextbox = QLineEdit(w)
myTextbox.move(20, 20)
myTextbox.resize(360,40)

# ------------------------------------------
# -- Create combobox
# ------------------------------------------
combo = QComboBox(w)
combo.addItem("--SECTION--")
combo.addItem("Python")
combo.addItem("Perl")
combo.addItem("Java")
combo.addItem("C++")
combo.move(20,70)

# ------------------------------------------
# -- Create the actions
# ------------------------------------------
myTextbox.setText('list count of combobox is ' + str(combo.count()) + '.')

@pyqtSlot()
def on_select():
result1 = combo.currentIndex()
result2 = combo.currentText()
myTextbox.setText("You've chosen combo list: " + result2 +"(" + str(result1) + " index)")


# ------------------------------------------
# -- Connect the signals to the slots
# ------------------------------------------
combo.currentIndexChanged.connect(on_select)


# ------------------------------------------
# -- Show the window and run the app
# ------------------------------------------
w.show()
myApp.exec_()



반응형

+ Recent posts