python gui界面实例-python GUI实战项目——tkinter库的简单实例

本文记录了一个使用Python GUI库tkinter和cx_Oracle数据库操作的实践项目,实现了增删改查功能。通过链接数据库,创建存储过程简化Python代码,并展示了tkinter界面的搭建和事件绑定,如查询、更新、删除操作。项目源代码和文件提供链接。
摘要由CSDN通过智能技术生成

一、项目说明:

本次通过实现一个小的功能模块对Python GUI进行实践学习。项目来源于软件制造工程的作业。记录在这里以复习下思路和总结编码过程。所有的源代码和文件放在这里:

链接: https://pan.baidu.com/s/1qXGVRB2 密码: 4a4r

内置四个文件,分别是ora.sql, dataBaseOpr.py, guiPy.py, test.py

二、效果预览:

828214-20171007083032318-501050226.png

主界面

828214-20171007083211021-1022688715.png

新增界面(更新界面一致)

功能很简单,就是做一张表的增删改查,借此简单的熟悉下python,前几天才看了看相关的语法。

三、环境说明:

数据库采用oracle12c,使用命令行进行操作。Python版本为3.6.2,命令行+Pycharm社区版2017.1.4。Python库使用了

cx_Oracle: 连接oracle数据库

tkinter: 简单入门的GUI库

cx_Oracle库的安装我直接使用IDE自带的包管理进行下载安装的,tkinter是Python3.2以后自带的标准库,后面会讲。

四、编码过程实现:

1、数据库表实现(ora.sql):

828214-20171007084646724-565141838.png

conn username/pass 根据本机的用户名和密码修改,后面的数据库连接统一都用我自己密码,不再赘述。

828214-20171007084938818-323644796.png

828214-20171007084909036-1204279914.png

为了简化Python代码和实践sql能力,写了两个简单的存储过程,分别是插入和更新,成功创建后只需调用存储过程和传递参数列表即可。代码详情在ora.sql中。

代码折叠:

ContractedBlock.gif

ExpandedBlockStart.gif

1 conn c##bai/bai1232 --建表

3 create or replace tablegroupinfo (4 no varchar(12) not null,5 name varchar(20),6 headername varchar(20),7 tel varchar(15),8 constraint pk_groupinfo primary key(no));9

10 --创建过程,直接传入参数即可插入

11 create or replace procedureinsert_groupinfo12 (no groupinfo.no%type,13 name groupinfo.name%type,14 headername groupinfo.headername%type,15 tel groupinfo.tel%type16 )17 is

18 begin

19 insert into groupinfo values(no,name,headername,tel);20 commit;21 end;22

23 --创建过程,直接传入参数即可完成更新,第一个字段为原纪录no。必须有。

24 create or replace procedureupdate_groupinfo25 (oldno groupinfo.no%type,26 no groupinfo.no%type,27 name groupinfo.name%type,28 headername groupinfo.headername%type,29 tel groupinfo.tel%type30 )31 is

32 n_no groupinfo.no%type;33 n_name groupinfo.name%type;34 n_headername groupinfo.headername%type;35 n_tel groupinfo.tel%type;36 grow groupinfo%rowtype;37 ex_oldnoisnull exception;38 begin

39 select * into grow from groupinfo g where g.no=oldno;40 if oldno is null or grow.no is null then

41 raise ex_oldnoisnull;42 end if;43 if no is null then

44 n_no:=oldno;45 else

46 n_no:=no;47 end if;48 if name is null then

49 n_name:=grow.name;50 else

51 n_name:=name;52 end if;53 if headername is null then

54 n_headername:=grow.headername;55 else

56 n_headername:=headername;57 end if;58 if tel is null then

59 n_tel:=grow.tel;60 else

61 n_tel:=tel;62 end if;63 --dbms_output.put_line(n_no||n_name||n_headername||n_tel);

64 update groupinfo g set g.no = n_no, g.name = n_name, g.headername = n_headername, g.tel = n_tel where g.no =oldno;65 commit;66 exception67 when ex_oldnoisnull then

68 dbms_output.out_line('选择的行不存在')69 end;

ora.sql

2、数据库操作类(dataBaseOpr.py):

先贴源码,折叠起来:

ContractedBlock.gif

ExpandedBlockStart.gif

1 #!/usr/bin/env python

2 #encoding: utf-8

3 """

4 :author: xiaoxiaobai5

6 :contact: 865816863@qq.com7

8 :file: dataBaseOpr.py9

10 :time: 2017/10/3 12:0411

12 :@Software: PyCharm Community Edition13

14 :desc: 连接oracle数据库,并封装了增删改查全部操作。15

16 """

17 importcx_Oracle18

19

20 classOracleOpr:21

22 def __init__(self, username='c##bai', passname='bai123

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值