资源简介
使用python3.6+sqlite3 创建数据库并实现增删改查操作
代码片段和文件信息
import tkinter as tk
from tkinter import *
from tkinter.ttk import *
from tkinter import ttk #导入内部包
import sqlite3 as sqlite
import os.path as op
import datetime
import time
class userManger():
“““docstring for userManger“““
def __init__(self):
super().__init__()
self.root = Tk()
self.root.title(“sqlite数据库测试“)
self.root.geometry(“350x350+450+300“)
self.addbtn = Button(self.roottext=“新增“command = self.adduser)
self.upbtn = Button(self.roottext=“修改“command = self.upuser)
self.delbtn = Button(self.roottext=“删除“command = self.deluser)
self.selbtn = Button(self.roottext=“查询“command = self.seluser)
self.clbtn = Button(self.roottext=“清空文本域“command = self.clear)
self.lab = tk.Label(self.roottext=““fg=“red“)
self.addbtn.grid(row=0column=0)
self.upbtn.grid(row=1column=0)
self.delbtn.grid(row=2column=0)
self.selbtn.grid(row=3column=0)
self.clbtn.grid(row=4column=0)
self.lab.grid(row=5column=0)
self.textMsg = tk.Text(self.root width=45 height=10 fg=“orangered“font = (‘‘ ‘9‘ ‘bold‘))
self.textMsg.grid(row=6column=0)
if not op.exists(‘test.db‘): #判断数据库是否存在,不存在则新建
self.createtabel()
self.root.mainloop()
def clear(self):
self.textMsg.delete(0.0 END)
def adduser(self): #新增
localtime = time.strftime(‘%Y-%m-%d %H:%M:%S‘ time.localtime(time.time())) # 时间格式化
conn = sqlite.connect(‘test.db‘)
cursor = conn.cursor()
sql = “insert into user (u_nameu_passwordb_time) values (???);“
v = (‘111‘‘111‘localtime)
try:
cursor.execute(sqlv)
conn.commit()
self.lab[“text“] = “新增成功“
except:
self.lab[“text“] = “新增失败“
conn.rollback()# 如果发生错误则回滚
cursor.close()#关闭游标
conn.close()#释放数据库资源
def upuser(self): #修改
localtime = time.strftime(‘%Y-%m-%d %H:%M:%S‘ time.localtime(time.time())) # 时间格式化
conn = sqlite.connect(‘test.db‘)
curso
相关资源
- 二级考试python试题12套(包括选择题和
- pywin32_python3.6_64位
- python+ selenium教程
- PycURL(Windows7/Win32)Python2.7安装包 P
- 英文原版-Scientific Computing with Python
- 7.图像风格迁移 基于深度学习 pyt
- 基于Python的学生管理系统
- A Byte of Python(简明Python教程)(第
- Python实例174946
- Python 人脸识别
- Python 人事管理系统
- 基于python-flask的个人博客系统
- 计算机视觉应用开发流程
- python 调用sftp断点续传文件
- python socket游戏
- 基于Python爬虫爬取天气预报信息
- python函数编程和讲解
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- python实现自动操作windows应用
- python人脸识别(opencv)
- python 绘图(方形、线条、圆形)
- python疫情卡UN管控
- python 连连看小游戏源码
- 基于PyQt5的视频播放器设计
- 一个简单的python爬虫
- csv文件行列转换python实现代码
- Python操作Mysql教程手册
- Python Machine Learning Case Studies
- python获取硬件信息
评论
共有 条评论