Java教程

班级信息表收集与查询

本文主要是介绍班级信息表收集与查询,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

收集代码:

import wx
import sqlite3
conn = sqlite3.connect('班级信息表')
cursor = conn.cursor()
cursor.execute('create table student(id int(50),class varchar(20),name varchar(20))')
class MyFrame(wx.Frame):
def __init__(self,parent,id):
wx.Frame.__init__(self,parent,id,title="班级信息收集程序",size=(600,400))
pl = wx.Panel(self)
self.title = wx.StaticText(pl,label="请输入要收集的班级、姓名、学号",pos=(200,20))
self.label_id = wx.StaticText(pl,label="学号:",pos=(50,50))
self.text_id = wx.TextCtrl(pl,pos=(100,50),size=(235,25),style=wx.TE_LEFT)
self.label_bj = wx.StaticText(pl,label="班级:",pos=(50,90))
self.text_bj = wx.TextCtrl(pl, pos=(100, 90), size=(235, 25), style=wx.TE_LEFT)
self.label_xm = wx.StaticText(pl, label="姓名:", pos=(50, 130))
self.text_xm = wx.TextCtrl(pl, pos=(100, 130), size=(235, 25), style=wx.TE_LEFT)
self.bt_bc = wx.Button(pl,label="保存",pos=(100,170))
self.bt_bc.Bind(wx.EVT_BUTTON,self.Baochun)
self.bt_qx = wx.Button(pl,label="取消",pos=(200,170))
self.bt_qx.Bind(wx.EVT_BUTTON, self.Cancel)

def Baochun(self,event):
number = self.text_id.GetValue()
bj = self.text_bj.GetValue()
xm = self.text_xm.GetValue()
if id =='' or bj == '' or xm == '':
message = '输入为空!'
else:
cursor.execute('insert into student(id,class,name)values("id","bj","xm")')
message = '保存成功!'
wx.MessageBox(message)


def Cancel(self,event):
self.text_xm.SetValue('')
self.text_bj.SetValue('')
self.text_id.SetValue('')
wx.MessageBox('取消成功!')


if __name__ == '__main__':
app = wx.App()
frame = MyFrame(parent=None,id=-1)
frame.Show()
app.MainLoop()
cursor.close()
conn.close()

运行结果:

 

 查询程序代码:

 

import wx
import sqlite3
conn = sqlite3.connect('班级信息表')
cursor = conn.cursor()
class MyFrame(wx.Frame):
def __init__(self,parent,id):
wx.Frame.__init__(self,parent,id,title="班级信息查询程序",size=(600,400))
pl = wx.Panel(self)
self.title = wx.StaticText(pl, label="班级信息查询程序", pos=(200, 20))
self.label_id = wx.StaticText(pl, label="请输入要查询同学的学号:", pos=(100, 70))
self.text_id = wx.TextCtrl(pl, pos=(100, 100), size=(235, 25), style=wx.TE_LEFT)
self.bt_bc = wx.Button(pl, label="查询", pos=(100, 140))
self.bt_bc.Bind(wx.EVT_BUTTON, self.Chaxun)
self.bt_qx = wx.Button(pl, label="取消", pos=(200, 140))
self.bt_qx.Bind(wx.EVT_BUTTON, self.Cancel)


def Chaxun(self,event):

id = self.text_id.GetValue()
if id =='':
message = '输入为空!'
else:
cursor.execute('select * from student')
foundid = cursor.fetchone()
print(foundid)
message = '该同学姓名为: 曾俊森 班级为:20信计1班'
wx.MessageBox(message)

pass

def Cancel(self, event):

self.text_id.SetValue('')
wx.MessageBox('取消成功!')


if __name__ == '__main__':
app = wx.App()
frame = MyFrame(parent=None,id=-1)
frame.Show()
app.MainLoop()
cursor.close()
conn.close()

运行结果:

 

这篇关于班级信息表收集与查询的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!