The following is a simple UI, it contains the label, lineEdit, checkbox and combobox components.
When I press the button, I want to insert those data of components to sqlite , but I do not know how to use.
I checked a lot of information on the Internet , but it always shows that connect to sqlite with C++.
#!/usr/bin/python
# sqlite_test.py
import sys
from PyQt4 import QtGui, QtCore
class MainWindow(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.resize(450, 250)
self.setWindowTitle('sqlitetest')
name = QtGui.QLabel('Name :', self)
name.move(100, 10)
nameEdit = QtGui.QLineEdit(self)
nameEdit.move(140, 10)
age = QtGui.QLabel('Age :', self)
age.move(100, 50)
ageEdit = QtGui.QLineEdit(self)
ageEdit.move(140, 50)
gender = QtGui.QLabel('Gender :', self)
gender.move(100, 90)
self.cb = QtGui.QCheckBox('boy', self)
self.cb.move(150, 90)
self.cb = QtGui.QCheckBox('girl', self)
self.cb.move(200, 90)
habit = QtGui.QLabel('Habit :', self)
habit.move(100, 130)
habitcombo = QtGui.QComboBox(self)
habitcombo.move(140, 130)
habitcombo.addItem("play basketball")
habitcombo.addItem("biking")
habitcombo.addItem("reading")
habitcombo.addItem("other")
self.button()
def button(self):
button1= QtGui.QPushButton('submit', self)
button1.setGeometry(300, 180, 70, 30)
self.connect(button1, QtCore.SIGNAL('clicked()'),
self.buttonClicked)
def buttonClicked(self):
sender = self.sender()
self.statusBar().showMessage(sender.text() + ' was pressed .')
app = QtGui.QApplication(sys.argv)
sql= MainWindow()
sql.show()
sys.exit(app.exec_())
Aucun commentaire:
Enregistrer un commentaire