建立一个sqlit数据库,保存我们的图书信息,建立我们的数据表
软件界面如下:
我们需要借助wxpython来建立我们的软件GUI界面,建立一个类(对象)来对我们的数据进行写入,将我们输入的信息写入到我们的数据库中,从而实现我们的目标
具体代码如下:
import sqlite3 as sq
import wx
APP_TITLE = u'Database entry'
class Book(object):
def __init__(self,name="",author="",quantity=0):
self.setName(name) #Initialization function type
self.setAuthor(author) #Initialization function type
self.setQuantity(quantity) #Initialization function type
def setName(self,name):
if not isinstance(name,str):
print('name must be string.')
return
self.__name = name
def setAuthor(self,author):
if not isinstance(author,str):
print('author must be string.')
return
self.__author = author
def setQuantity(self,quantity):
if not isinstance(quantity,int):
print('quantity must be integer.')
return
self.__quantity = quantity
def show(self):
print(self.__name)
print(self.__author)
print(self.__quantity)
class Computerbook(Book):
def __init__(self,name='',author='',quantity=1,computerField="python programming"):
self.setName(name) #Initialization function type
self.setAuthor(author) #Initialization function type
self.setQuantity