GUI程序设计--班级信息收集系

import wx
import pymysql

#主要窗口类
class LoginFrame(wx.Frame):
    def __init__(self,parent,id):
        wx.Frame.__init__(self,parent,id,'用户登录及注册',pos = (700,400),size=(400,250))
        panel = wx.Panel(self)
        
        self.bt_confirm = wx.Button(panel,label = '查询')
        self.bt_confirm.Bind(wx.EVT_BUTTON,self.selectController)
        self.bt_cancel = wx.Button(panel,label = '注册')
        self.bt_cancel.Bind(wx.EVT_BUTTON,self.registerController)
        
        self.title = wx.StaticText(panel, label = '支持输入姓名查询学号,没注册的输入名字以及学号将自动注册')
        self.label_user = wx.StaticText(panel, label = '姓名')
        self.text_user = wx.TextCtrl(panel, style = wx.TE_LEFT)
        self.label_userid = wx.StaticText(panel, label = '学号')
        self.text_userid = wx.TextCtrl(panel, style = wx.TE_LEFT)
        
        hsizer_user = wx.BoxSizer(wx.HORIZONTAL)
        hsizer_user.Add(self.label_user, proportion = 0,flag = wx.ALL,border = 5)
        hsizer_user.Add(self.text_user, proportion = 1,flag = wx.ALL,border = 5)
        hsizer_userid = wx.BoxSizer(wx.HORIZONTAL)
        hsizer_userid.Add(self.label_userid, proportion = 0,flag = wx.ALL,border = 5)
        hsizer_userid.Add(self.text_userid, proportion = 1,flag = wx.ALL,border = 5)
        hsizer_button = wx.BoxSizer(wx.HORIZONTAL)
        hsizer_button.Add(self.bt_confirm, proportion = 0,flag = wx.ALL,border = 5)
        hsizer_button.Add(self.bt_cancel, proportion = 0,flag = wx.ALL,border = 5)
        
        viszer_all = wx.BoxSizer(wx.VERTICAL)
        viszer_all.Add(self.title, proportion = 0, flag = wx.BOTTOM|wx.TOP|wx.ALIGN_CENTER, border = 15)
        viszer_all.Add(hsizer_user, proportion = 0, flag = wx.EXPAND|wx.LEFT|wx.RIGHT, border = 45)
        viszer_all.Add(hsizer_userid, proportion = 0, flag = wx.EXPAND|wx.LEFT|wx.RIGHT, border = 45)
        viszer_all.Add(hsizer_button, proportion = 0, flag = wx.ALIGN_CENTER|wx.TOP, border = 15)
        panel.SetSizer(viszer_all)
        
    '''
        没将判断逻辑做好
        查询要是不存在在数据库中那直接就不能在后面继续使用,没找到解决办法
    '''
    #控制查询方法
    def selectController(self, event):
        username = self.text_user.GetValue()
        result = selectOne(username)
        wx.MessageBox(username+'的学号为:'+result[0])
        
     #控制写入方法  
    def registerController(self, event):
        insertOne(self.text_userid.GetValue(),self.text_user.GetValue())
        wx.MessageBox('添加成功')

#链接数据库并查询语句        
def selectOne(username):
        conn = pymysql.connect(host='localhost',user='root',password='1002466752asdfgHJKL',database='studentinformation')
        cursor = conn.cursor()
        cursor.execute("select * from information where username = %s",(username,))
        result = cursor.fetchone()
        cursor.close()
        conn.close()
        return result

#链接数据库并输入语句    
def insertOne(userid,username):
        conn = pymysql.connect(host='localhost',user='root',password='1002466752asdfgHJKL',database='studentinformation')
        cursor = conn.cursor()
        cursor.execute("insert into information (userid,username) values (%s,%s)",(userid,username))
        cursor.close()
        conn.commit()
        conn.close()
    
if __name__ == '__main__':
    app = wx.App()
    frame = LoginFrame(parent = None, id = -1)
    frame.Show()
    app.MainLoop()

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值