We have various widgets that we can access with PyQT. Including:
- Textbox
- Combobox
- Calendar
For more widgets we suggest using the GUI creation tool covered in the next tutorial.
Related course: Create GUI Apps with PyQt5
Textbox widget
Input fields are present in nearly every application. In PyQT4 an input field can be created using the QLineEdit() function.
import sys from PyQt4.QtGui import *
a = QApplication(sys.argv)
w = QMainWindow()
w.resize(320, 100)
w.setWindowTitle("PyQT Python Widget!")
textbox = QLineEdit(w) textbox.move(20, 20) textbox.resize(280,40)
w.show()
sys.exit(a.exec_())
|
qt textbox
Combobox
A combobox can be used to select an item from a list.
import sys from PyQt4.QtGui import *
a = QApplication(sys.argv)
w = QMainWindow()
w.resize(320, 100)
w.setWindowTitle("PyQT Python Widget!")
combo = QComboBox(w) combo.addItem("Python") combo.addItem("Perl") combo.addItem("Java") combo.addItem("C++") combo.move(20,20)
w.show()
sys.exit(a.exec_())
|
qt combobox
Calendar widget
The PyQT4 library has a calendar widget, you can create it using the QCalendarWidget() call.
import sys from PyQt4.QtGui import *
a = QApplication(sys.argv)
w = QMainWindow()
w.resize(320, 240)
w.setWindowTitle("PyQT Python Widget!")
cal = QCalendarWidget(w) cal.setGridVisible(True) cal.move(0, 0) cal.resize(320,240)
w.show()
sys.exit(a.exec_())
|
Result:
calendar qt
Download PyQT Code (Bulk Collection)