# -*- coding: utf-8 -*- from form1 import * from MySQLdb import connections class Form1Impl(Form1): def __init__(self): Form1.__init__(self) self.connect(self.pushButton,SIGNAL("pressed()"),self.SlotInsert) self.db=connections.Connection(db='test', host='localhost', user='cetus') self.curs=self.db.cursor() self.Select() def Select(self): row=self.curs.execute("SELECT * from device;") self.table.setNumRows(row) rw=self.curs.fetchone() for i in range(row): self.table.setText(i,0,rw[1]) self.table.setText(i,1,str(rw[2])) rw=self.curs.fetchone() def SlotInsert(self): row=self.curs.execute("INSERT INTO device VALUES(0,'%s','%s')" % \ (self.lineEditName.text(),self.lineEditCost.text())) self.Select()