一 增加数据库界面
1 代码
# -*- coding: utf-8 -*-
###########################################################################
## Python code generated with wxFormBuilder (version Feb 16 2016)
## http://www.wxformbuilder.org/
##
## PLEASE DO "NOT" EDIT THIS FILE!
###########################################################################
import wx
import wx.xrc
from SaveZiDuan import MyFrame5
from SaveDataBase import MyFrame9
from SaveDocument_Window import MyFrame31
###########################################################################
## Class MyFrame7
###########################################################################
class MyFrame7(wx.Frame):
def __init__(self, parent):
#框架初始化
wx.Frame.__init__(self, parent, id=wx.ID_ANY, title=wx.EmptyString,
pos=wx.DefaultPosition,size=wx.Size(477, 141),
style=wx.DEFAULT_FRAME_STYLE | wx.TAB_TRAVERSAL)
#Windows类的方法
self.SetSizeHintsSz(wx.DefaultSize, wx.DefaultSize)
#垂直和水平布局控制器
bSizer7 = wx.BoxSizer(wx.VERTICAL)
bSizer8 = wx.BoxSizer(wx.HORIZONTAL)
#空白标签,位于布局控制器8
self.m_staticText6 = wx.StaticText(self, wx.ID_ANY, wx.EmptyString,
wx.DefaultPosition, wx.Size(100, 50), 0)
self.m_staticText6.Wrap(-1)
bSizer8.Add(self.m_staticText6, 0, wx.ALL, 5)
#增加DATABASE按钮,位于布局控制器8
self.m_button2 = wx.Button(self, wx.ID_ANY, u"增加DATABASE",
wx.DefaultPosition, wx.Size(120, 50), 0)
bSizer8.Add(self.m_button2, 0, wx.ALL, 5)
#添加TABLE按钮,位于布局控制器8
self.m_button3 = wx.Button(self, wx.ID_ANY, u"增加TABLE",
wx.DefaultPosition, wx.Size(120, 50), 0)
bSizer8.Add(self.m_button3, 0, wx.ALL, 5)
#布局控制器8位于布局控制器7
bSizer7.Add(bSizer8, 0, wx.EXPAND, 5)
#水平布局控制器
bSizer9 = wx.BoxSizer(wx.HORIZONTAL)
#空白标签位于布局控制器9
self.m_staticText7 = wx.StaticText(self, wx.ID_ANY, wx.EmptyString,
wx.DefaultPosition, wx.Size(100, 50), 0)
self.m_staticText7.Wrap(-1)
bSizer9.Add(self.m_staticText7, 0, wx.ALL, 5)
#增加数据位于布局控制器9
self.m_button4 = wx.Button(self, wx.ID_ANY, u"增加数据",
wx.DefaultPosition, wx.Size(120, 50), 0)
bSizer9.Add(self.m_button4, 0, wx.ALL, 5)
#退出,位于布局控制器9
self.m_button5 = wx.Button(self, wx.ID_ANY, u"退出",
wx.DefaultPosition, wx.Size(120, 50), 0)
bSizer9.Add(self.m_button5, 0, wx.ALL, 5)
#布局控制器9位于布局控制器7上
bSizer7.Add(bSizer9, 0, wx.EXPAND, 5)
#Window类的方法
self.SetSizer(bSizer7)
self.Layout()
self.Centre(wx.BOTH)
# 按钮绑定事件
self.m_button2.Bind(wx.EVT_BUTTON, self.m_button2OnButtonClick)
self.m_button3.Bind(wx.EVT_BUTTON, self.m_button3OnButtonClick)
self.m_button4.Bind(wx.EVT_BUTTON, self.m_button4OnButtonClick)
self.m_button5.Bind(wx.EVT_BUTTON, self.m_button5OnButtonClick)
def __del__(self):
pass
# 点击按钮,弹出对应的窗口
def m_button2OnButtonClick(self, event):
window=MyFrame9(None)
window.Show()
def m_button3OnButtonClick(self, event):
window=MyFrame5(None)
window.Show()
def m_button4OnButtonClick(self, event):
window=MyFrame31(None)
window.Show()
def m_button5OnButtonClick(self, event):
exit()
#测试
if __name__=='__main__':
app=wx.App()
window=MyFrame7(None)
window.Show()
app.MainLoop()
2 运行结果
二 新建一个数据库
1 代码
# -*- coding: utf-8 -*-
###########################################################################
## Python code generated with wxFormBuilder (version Feb 16 2016)
## http://www.wxformbuilder.org/
##
## PLEASE DO "NOT" EDIT THIS FILE!
###########################################################################
import wx
import wx.xrc
from CreateDatabase import CreateDatabase
from Notice import MyFrame3
###########################################################################
## Class MyFrame9
###########################################################################
class MyFrame9(wx.Frame):
def __init__(self, parent):
#初始化框架
wx.Frame.__init__(self, parent, id=wx.ID_ANY, title=wx.EmptyString,
pos=wx.DefaultPosition,size=wx.Size(500, 300),
style=wx.DEFAULT_FRAME_STYLE | wx.TAB_TRAVERSAL)
#Windows类的方法
self.SetSizeHintsSz(wx.DefaultSize, wx.DefaultSize)
#垂直和水平布局控制器
bSizer10 = wx.BoxSizer(wx.VERTICAL)
bSizer11 = wx.BoxSizer(wx.HORIZONTAL)
#输入数据库名提示,位于布局控制器11
self.m_staticText8 = wx.StaticText(self, wx.ID_ANY,
u"请输入DATABASE名称",
wx.DefaultPosition, wx.Size(150, 50), 0)
self.m_staticText8.Wrap(-1)
bSizer11.Add(self.m_staticText8, 0, wx.ALL, 5)
#要添加的数据库名,位于布局控制器11
self.m_textCtrl6 = wx.TextCtrl(self, wx.ID_ANY,
wx.EmptyString, wx.DefaultPosition,
wx.Size(120, 50), 0)
bSizer11.Add(self.m_textCtrl6, 0, wx.ALL, 5)
#布局控制器11在布局控制器10中
bSizer10.Add(bSizer11, 1, wx.EXPAND, 5)
#水平布局控制器
bSizer12 = wx.BoxSizer(wx.HORIZONTAL)
#空白标签,位于布局控制器12
self.m_staticText9 = wx.StaticText(self, wx.ID_ANY,
wx.EmptyString, wx.DefaultPosition,
wx.Size(150, 50), 0)
self.m_staticText9.Wrap(-1)
bSizer12.Add(self.m_staticText9, 0, wx.ALL, 5)
#确认按钮,位于布局控制器12
self.m_button6 = wx.Button(self, wx.ID_ANY, u"确定",
wx.DefaultPosition, wx.Size(120, 50), 0)
bSizer12.Add(self.m_button6, 0, wx.ALL, 5)
#布局控制器12位于布局控制器10
bSizer10.Add(bSizer12, 1, wx.EXPAND, 5)
#Window类的方法
self.SetSizer(bSizer10)
self.Layout()
self.Centre(wx.BOTH)
# 按钮绑定事件
self.m_button6.Bind(wx.EVT_BUTTON, self.m_button6OnButtonClick)
def __del__(self):
pass
# 点击按钮,新建一个数据库
def m_button6OnButtonClick(self, event):
dataname=self.m_textCtrl6.GetValue()
sql='create database %s'%dataname
createdatabase=CreateDatabase(sql)
if(dataname):
window=MyFrame3(None)
window.Show()
else:
window=MyFrame3(None,'请检查DATABASE名称是否输入!')
window.Show()
#测试
if __name__=='__main__':
app=wx.App()
window=MyFrame9(None)
window.Show()
app.MainLoop()
2 测试
三 给数据库新增一张数据表
1 代码
# -*- coding: utf-8 -*-
###########################################################################
## Python code generated with wxFormBuilder (version Feb 16 2016)
## http://www.wxformbuilder.org/
##
## PLEASE DO "NOT" EDIT THIS FILE!
###########################################################################
import wx
import wx.xrc
from CreateTable import CreateTable
from Notice import MyFrame3
###########################################################################
## Class MyFrame5
###########################################################################
class MyFrame5(wx.Frame):
def __init__(self, parent):
#框架初始化
wx.Frame.__init__(self, parent, id=wx.ID_ANY, title=wx.EmptyString,
pos=wx.DefaultPosition,size=wx.Size(763, 477),
style=wx.DEFAULT_FRAME_STYLE | wx.TAB_TRAVERSAL)
#Window类的方法
self.SetSizeHintsSz(wx.DefaultSize, wx.DefaultSize)
#垂直和水平布局控制器
bSizer1 = wx.BoxSizer(wx.VERTICAL)
bSizer2 = wx.BoxSizer(wx.HORIZONTAL)
#提示信息,位于布局控制器2
self.m_staticText1 = wx.StaticText(self, wx.ID_ANY,
u"请输入第一个字段和数据类型",
wx.DefaultPosition, wx.Size(130, 50), 0)
self.m_staticText1.Wrap(-1)
bSizer2.Add(self.m_staticText1, 0, wx.ALL, 5)
#第一个字段的名称,位于布局控制器2
self.m_textCtrl1 = wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString,
wx.DefaultPosition, wx.Size(130, 50), 0)
bSizer2.Add(self.m_textCtrl1, 0, wx.ALL, 5)
#第一个字段的类型,位于布局控制器2
self.m_textCtrl7 = wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString,
wx.DefaultPosition, wx.Size(100, 50), 0)
bSizer2.Add(self.m_textCtrl7, 0, wx.ALL, 5)
#主键复选框,位于布局控制器2
self.m_checkBox1 = wx.CheckBox(self, wx.ID_ANY, u"PRIMARY KEY",
wx.DefaultPosition, wx.Size(130, 50), 0)
bSizer2.Add(self.m_checkBox1, 0, wx.ALL, 5)
#自增复选框,位于布局控制器2
self.m_checkBox2 = wx.CheckBox(self, wx.ID_ANY, u"AUTO_INCREMENT",
wx.DefaultPosition, wx.Size(-1, 50), 0)
bSizer2.Add(self.m_checkBox2, 0, wx.ALL, 5)
#布局控制器2位于布局控制器1
bSizer1.Add(bSizer2, 0, wx.EXPAND, 5)
#水平布局控制器
bSizer3 = wx.BoxSizer(wx.HORIZONTAL)
#提示信息,位于布局控制器3
self.m_staticText2 = wx.StaticText(self, wx.ID_ANY, u"请输入第二个字段和数据类型",
wx.DefaultPosition, wx.Size(130, 50), 0)
self.m_staticText2.Wrap(-1)
bSizer3.Add(self.m_staticText2, 0, wx.ALL, 5)
#第2个字段名称,位于布局控制器3
self.m_textCtrl2 = wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString,
wx.DefaultPosition, wx.Size(130, 50), 0)
bSizer3.Add(self.m_textCtrl2, 0, wx.ALL, 5)
#第2个字段的类型,位于布局控制器3
self.m_textCtrl8 = wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString,
wx.DefaultPosition, wx.Size(100, 50), 0)
bSizer3.Add(self.m_textCtrl8, 0, wx.ALL, 5)
#选择列表,主键或自增量,位于布局控制器3
m_comboBox3Choices = [u"PRIMARY KEY", u"AUTO_INCREMENT"]
self.m_comboBox3 = wx.ComboBox(self, wx.ID_ANY, u"主键、自增",
wx.DefaultPosition, wx.Size(130, 50),
m_comboBox3Choices, 0)
bSizer3.Add(self.m_comboBox3, 0, wx.ALL, 5)
#控制器3位于控制器1
bSizer1.Add(bSizer3, 0, wx.EXPAND, 5)
#第3个字段
bSizer4 = wx.BoxSizer(wx.HORIZONTAL)
self.m_staticText3 = wx.StaticText(self, wx.ID_ANY,
u"请输入第三个字段和数据类型",
wx.DefaultPosition, wx.Size(130, 50), 0)
self.m_staticText3.Wrap(-1)
bSizer4.Add(self.m_staticText3, 0, wx.ALL, 5)
self.m_textCtrl3 = wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString,
wx.DefaultPosition, wx.Size(130, 50), 0)
bSizer4.Add(self.m_textCtrl3, 0, wx.ALL, 5)
self.m_textCtrl9 = wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString,
wx.DefaultPosition, wx.Size(100, 50), 0)
bSizer4.Add(self.m_textCtrl9, 0, wx.ALL, 5)
bSizer1.Add(bSizer4, 0, wx.EXPAND, 5)
#第4个字段
bSizer5 = wx.BoxSizer(wx.HORIZONTAL)
self.m_staticText4 = wx.StaticText(self, wx.ID_ANY,
u"请输入第四个字段和数据类型",
wx.DefaultPosition, wx.Size(130, 50), 0)
self.m_staticText4.Wrap(-1)
bSizer5.Add(self.m_staticText4, 0, wx.ALL, 5)
self.m_textCtrl4 = wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString,
wx.DefaultPosition, wx.Size(130, 50), 0)
bSizer5.Add(self.m_textCtrl4, 0, wx.ALL, 5)
self.m_textCtrl10 = wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString,
wx.DefaultPosition, wx.Size(100, 50), 0)
bSizer5.Add(self.m_textCtrl10, 0, wx.ALL, 5)
self.m_staticText9 = wx.StaticText(self, wx.ID_ANY,
u"如果字段数量或者关键字不匹配请使用首页的SQL语句传入",
wx.DefaultPosition, wx.Size(300, 50), 0)
self.m_staticText9.Wrap(-1)
self.m_staticText9.SetFont(wx.Font(13, 74, 90, 90, False, "Sans"))
bSizer5.Add(self.m_staticText9, 0, wx.ALL, 5)
bSizer1.Add(bSizer5, 0, wx.EXPAND, 5)
#第5个字段
bSizer6 = wx.BoxSizer(wx.HORIZONTAL)
self.m_staticText5 = wx.StaticText(self, wx.ID_ANY,
u"请输入第五个字段和数据类型",
wx.DefaultPosition, wx.Size(130, 50), 0)
self.m_staticText5.Wrap(-1)
bSizer6.Add(self.m_staticText5, 0, wx.ALL, 5)
self.m_textCtrl5 = wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString,
wx.DefaultPosition, wx.Size(130, 50), 0)
bSizer6.Add(self.m_textCtrl5, 0, wx.ALL, 5)
self.m_textCtrl11 = wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString,
wx.DefaultPosition, wx.Size(100, 50), 0)
bSizer6.Add(self.m_textCtrl11, 0, wx.ALL, 5)
bSizer1.Add(bSizer6, 0, wx.EXPAND, 5)
#表名
bSizer7 = wx.BoxSizer(wx.HORIZONTAL)
self.m_staticText7 = wx.StaticText(self, wx.ID_ANY, u"请输入表名",
wx.DefaultPosition, wx.Size(130, 50), 0)
self.m_staticText7.Wrap(-1)
bSizer7.Add(self.m_staticText7, 0, wx.ALL, 5)
self.m_textCtrl6 = wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString,
wx.DefaultPosition, wx.Size(130, 50), 0)
bSizer7.Add(self.m_textCtrl6, 0, wx.ALL, 5)
bSizer1.Add(bSizer7, 0, wx.EXPAND, 5)
#空白标签
bSizer8 = wx.BoxSizer(wx.HORIZONTAL)
self.m_staticText8 = wx.StaticText(self, wx.ID_ANY, wx.EmptyString,
wx.DefaultPosition, wx.Size(300, 50), 0)
self.m_staticText8.Wrap(-1)
bSizer8.Add(self.m_staticText8, 0, wx.ALL, 5)
#确认按钮
self.m_button2 = wx.Button(self, wx.ID_ANY, u"确定",
wx.DefaultPosition, wx.Size(130, 50), 0)
bSizer8.Add(self.m_button2, 0, wx.ALL, 5)
bSizer1.Add(bSizer8, 1, wx.EXPAND, 5)
#Window类的方法
self.SetSizer(bSizer1)
self.Layout()
self.Centre(wx.BOTH)
# 控件和事件绑定
self.m_checkBox1.Bind(wx.EVT_CHECKBOX, self.m_checkBox1OnCheckBox)
self.m_checkBox2.Bind(wx.EVT_CHECKBOX, self.m_checkBox2OnCheckBox)
self.m_comboBox3.Bind(wx.EVT_COMBOBOX, self.m_comboBox3OnCombobox)
self.m_button2.Bind(wx.EVT_BUTTON, self.m_button2OnButtonClick)
##################################
#主键复选框选择次数
self.count1=0
#自增量复选框选择次数
self.count2=0
self.check_box1=''
self.check_box2 = ''
self.combo_box=''
def __del__(self):
pass
# 当选择为奇数时,表示选择上,否则表示未选择上
def m_checkBox1OnCheckBox(self, event):
self.count1+=1
if(self.count1%2==1):
self.check_box1 = 'PRIMARY KEY'
else:
self.check_box1 = ''
# 当选择为奇数时,表示选择上,否则表示未选择上
def m_checkBox2OnCheckBox(self, event):
self.count2+=1
if(self.count2%2==1):
self.check_box2 = 'AUTO_INCREMENT'
else:
self.check_box2 = ''
# 获取列表选择框的值
def m_comboBox3OnCombobox(self, event):
self.combo_box = self.m_comboBox3.GetValue()
'''
分6种情况来创建表
'''
def m_button2OnButtonClick(self, event):
if(self.m_textCtrl1.GetValue()!='' and self.m_textCtrl2.GetValue()!=''
and self.m_textCtrl3.GetValue()!='' and self.m_textCtrl4.GetValue()!=''
and self.m_textCtrl5.GetValue()!=''):
sql = "create table %s(%s %s %s %s,%s %s %s,%s %s,%s %s,%s %s);" \
% (self.m_textCtrl6.GetValue(),
self.m_textCtrl1.GetValue(),self.m_textCtrl7.GetValue(),
self.check_box1,self.check_box2,
self.m_textCtrl2.GetValue(),self.m_textCtrl8.GetValue(),self.combo_box,
self.m_textCtrl3.GetValue(),self.m_textCtrl9.GetValue(),
self.m_textCtrl4.GetValue(),self.m_textCtrl10.GetValue(),
self.m_textCtrl5.GetValue(),self.m_textCtrl11.GetValue()
)
create=CreateTable(sql)
notice=MyFrame3(None)
notice.Show()
elif(self.m_textCtrl1.GetValue()!='' and self.m_textCtrl2.GetValue()!=''
and self.m_textCtrl3.GetValue()!='' and self.m_textCtrl4.GetValue()!=''):
sql = "create table %s(%s %s %s %s,%s %s %s,%s %s,%s %s);" \
% (self.m_textCtrl6.GetValue(),
self.m_textCtrl1.GetValue(),self.m_textCtrl7.GetValue(),self.check_box1,
self.check_box2,
self.m_textCtrl2.GetValue(),self.m_textCtrl8.GetValue(),self.combo_box,
self.m_textCtrl3.GetValue(),self.m_textCtrl9.GetValue(),
self.m_textCtrl4.GetValue(),self.m_textCtrl10.GetValue()
)
create=CreateTable(sql)
notice=MyFrame3(None)
notice.Show()
elif(self.m_textCtrl1.GetValue()!='' and self.m_textCtrl2.GetValue()!=''
and self.m_textCtrl3.GetValue()!=''):
sql = "create table %s(%s %s %s %s,%s %s %s,%s %s);" \
% (self.m_textCtrl6.GetValue(),
self.m_textCtrl1.GetValue(),self.m_textCtrl7.GetValue(),self.check_box1,
self.check_box2,
self.m_textCtrl2.GetValue(),self.m_textCtrl8.GetValue(),self.combo_box,
self.m_textCtrl3.GetValue(),self.m_textCtrl9.GetValue()
)
create=CreateTable(sql)
notice=MyFrame3(None)
notice.Show()
elif(self.m_textCtrl1.GetValue()!='' and self.m_textCtrl2.GetValue()!=''):
sql = "create table %s(%s %s %s %s,%s %s %s);" \
% (self.m_textCtrl6.GetValue(),
self.m_textCtrl1.GetValue(),self.m_textCtrl7.GetValue(),self.check_box1,
self.check_box2,
self.m_textCtrl2.GetValue(),self.m_textCtrl8.GetValue(),self.combo_box
)
create=CreateTable(sql)
notice=MyFrame3(None)
notice.Show()
elif(self.m_textCtrl1.GetValue()!=''):
sql = "create table %s(%s %s %s %s);" \
% (self.m_textCtrl6.GetValue(),
self.m_textCtrl1.GetValue(),self.m_textCtrl7.GetValue(),
self.check_box1,self.check_box2
)
create=CreateTable(sql)
notice=MyFrame3(None)
notice.Show()
elif(not (self.m_textCtrl1.GetValue()!='' and self.m_textCtrl2.GetValue()!=''
and self.m_textCtrl3.GetValue()!='' and self.m_textCtrl4.GetValue()!=''
and self.m_textCtrl5.GetValue()!='')):
notice = MyFrame3(None,"请检查是否输入了字段!")
notice.Show()
if __name__=='__main__':
app=wx.App()
window=MyFrame5(None)
window.Show()
app.MainLoop()
2 运行结果
四 保存数据记录
# -*- coding: UTF-8 -*-
import MySQLdb
from ReadCode import ReadCode
from Notice import MyFrame3
class SaveDocument():
def __init__(self,sql):
readcode = ReadCode()
Line = readcode.return_line()
# 打开数据库连接
db = MySQLdb.connect("localhost", "%s" % Line[0],
"%s" % Line[1], "%s" % Line[2])
# 使用cursor()方法获取操作游标
cursor = db.cursor()
# SQL 更新语句
try:
# 执行SQL语句
cursor.execute(sql)
# 提交到数据库执行
db.commit()
except:
db.rollback()
window=MyFrame3(None,"失败!")
window.Show()
# 关闭数据库连接
db.close()
五 数据记录保存
1 代码
# -*- coding: utf-8 -*-
###########################################################################
## Python code generated with wxFormBuilder (version Feb 16 2016)
## http://www.wxformbuilder.org/
##
## PLEASE DO "NOT" EDIT THIS FILE!
###########################################################################
import wx
import wx.xrc
from Check_Database import Check_Database
from Check_Desc import Check_Desc
from Save_Document import SaveDocument
from Notice import MyFrame3
###########################################################################
## Class MyFrame31
###########################################################################
class MyFrame31(wx.Frame):
def __init__(self, parent):
#初始化框架
wx.Frame.__init__(self, parent, id=wx.ID_ANY, title=wx.EmptyString,
pos=wx.DefaultPosition,size=wx.Size(652, 585),
style=wx.DEFAULT_FRAME_STYLE | wx.TAB_TRAVERSAL)
#Windows类的方法
self.SetSizeHintsSz(wx.DefaultSize, wx.DefaultSize)
#垂直布局管理器
bSizer1 = wx.BoxSizer(wx.VERTICAL)
bSizer3 = wx.BoxSizer(wx.VERTICAL)
#提示信息,位于布局控制器3
self.m_staticText3 = wx.StaticText(self, wx.ID_ANY, u"所有的表如下",
wx.DefaultPosition, wx.DefaultSize, 0)
self.m_staticText3.Wrap(-1)
self.m_staticText3.SetFont(wx.Font(22, 74, 90, 90, False, "Sans"))
bSizer3.Add(self.m_staticText3, 0, wx.ALL, 5)
#用于存放特定数据库的表,位于布局控制器3
self.m_textCtrl3 = wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString,
wx.DefaultPosition, wx.Size(800, 100),
style=wx.TE_MULTILINE|wx.TE_READONLY)
bSizer3.Add(self.m_textCtrl3, 0, wx.ALL, 5)
#布局控制器位于布局控制器1
bSizer1.Add(bSizer3, 0, wx.EXPAND, 5)
#水平布局控制器
bSizer2 = wx.BoxSizer(wx.HORIZONTAL)
#提示信息,位于布局控制器2
self.m_staticText1 = wx.StaticText(self, wx.ID_ANY, u"请输入想要输入数据的表名",
wx.DefaultPosition, wx.Size(200, 50), 0)
self.m_staticText1.Wrap(-1)
bSizer2.Add(self.m_staticText1, 0, wx.ALL, 5)
#要输入的表名,位于布局控制器2
self.m_textCtrl2 = wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString,
wx.DefaultPosition, wx.Size(200, 50), 0)
bSizer2.Add(self.m_textCtrl2, 0, wx.ALL, 5)
#确定按钮,位于布局控制器2
self.m_button1 = wx.Button(self, wx.ID_ANY, u"确定", wx.DefaultPosition
, wx.Size(100, 50), 0)
bSizer2.Add(self.m_button1, 0, wx.ALL, 5)
#布局控制器2位于布局控制1
bSizer1.Add(bSizer2, 0, wx.EXPAND, 5)
#垂直布局控制器
bSizer4 = wx.BoxSizer(wx.VERTICAL)
#表的自段信息提示
self.m_staticText4 = wx.StaticText(self, wx.ID_ANY, u"表中所有字段如下",
wx.DefaultPosition, wx.DefaultSize, 0)
self.m_staticText4.Wrap(-1)
bSizer4.Add(self.m_staticText4, 0, wx.ALL, 5)
self.m_textCtrl4 = wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString,
wx.DefaultPosition, wx.Size(800, 50),
style=wx.TE_MULTILINE|wx.TE_READONLY)
bSizer4.Add(self.m_textCtrl4, 0, wx.ALL, 5)
bSizer1.Add(bSizer4, 0, wx.EXPAND, 5)
bSizer5 = wx.BoxSizer(wx.VERTICAL)
self.m_staticText5 = wx.StaticText(self, wx.ID_ANY,
u"请输入想要存入的字段名(用“,”隔开)",
wx.DefaultPosition, wx.DefaultSize,0)
self.m_staticText5.Wrap(-1)
bSizer5.Add(self.m_staticText5, 0, wx.ALL, 5)
# 要存的字段名
self.m_textCtrl5 = wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString,
wx.DefaultPosition, wx.Size(800, 50), 0)
bSizer5.Add(self.m_textCtrl5, 0, wx.ALL, 5)
bSizer1.Add(bSizer5, 0, wx.EXPAND, 5)
bSizer6 = wx.BoxSizer(wx.VERTICAL)
self.m_staticText6 = wx.StaticText(self, wx.ID_ANY, u"请输入想要存入的字段的VALUES",
wx.DefaultPosition, wx.Size(-1, -1),0)
self.m_staticText6.Wrap(-1)
bSizer6.Add(self.m_staticText6, 0, wx.ALL, 5)
# 要存字段名的值
self.m_textCtrl6 = wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString,
wx.DefaultPosition, wx.Size(800, 50), 0)
bSizer6.Add(self.m_textCtrl6, 0, wx.ALL, 5)
bSizer1.Add(bSizer6, 0, wx.EXPAND, 5)
bSizer7 = wx.BoxSizer(wx.HORIZONTAL)
self.m_staticText7 = wx.StaticText(self, wx.ID_ANY, wx.EmptyString,
wx.DefaultPosition, wx.Size(240, 50), 0)
self.m_staticText7.Wrap(-1)
bSizer7.Add(self.m_staticText7, 0, wx.ALL, 5)
self.m_button2 = wx.Button(self, wx.ID_ANY, u"确定",
wx.DefaultPosition, wx.Size(100, 50), 0)
bSizer7.Add(self.m_button2, 0, wx.ALL, 5)
bSizer1.Add(bSizer7, 0, wx.EXPAND, 5)
self.SetSizer(bSizer1)
self.Layout()
self.Centre(wx.BOTH)
# 按钮绑定事件
self.m_button1.Bind(wx.EVT_BUTTON, self.m_button1OnButtonClick)
self.m_button2.Bind(wx.EVT_BUTTON, self.m_button2OnButtonClick)
#################################################################
#显示数据表
check_database=Check_Database('show tables')
show=''
for i in range(0,len(check_database.return_result)):
show+=check_database.return_result[i]
self.m_textCtrl3.SetValue(show)
def __del__(self):
pass
# 表结构
def m_button1OnButtonClick(self, event):
table_name=self.m_textCtrl2.GetValue()
desc=Check_Desc(table_name)
result=''
for i in range(0,len(desc.return_result)):
result+=desc.return_result[i]
self.m_textCtrl4.SetValue('%s'%result)
def m_button2OnButtonClick(self, event):
#获取字段
insert_ziduan = self.m_textCtrl5.GetValue()
#获得数据
insert_values=self.m_textCtrl6.GetValue()
sql="insert into %s(%s) VALUES(%s);"%(self.m_textCtrl2.GetValue(),
insert_ziduan,insert_values)
print sql
save_document=SaveDocument(sql)
notice=MyFrame3(None)
notice.Show()
#测试
if __name__=='__main__':
app=wx.App()
window=MyFrame31(None)
window.Show()
app.MainLoop()
2 运行结果