2 Star 2 Fork 0

daitianjun / booksystem

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
add.py 2.47 KB
一键复制 编辑 原始数据 按行查看 历史
daitianjun 提交于 2022-06-01 15:48 . '第一次提交'
# _*_ coding: utf-8 _*_
import sqlite3
import tkinter as tk
import tkinter.messagebox
from tkinter import ttk
from config import bg, bt_font, bt_bg, child_size
class Add(tk.Tk):
def __init__(self):
self.db = sqlite3.connect('static/data.db')
self.cursor = self.db.cursor()
super(Add, self).__init__()
self.configure(bg=bg)
self.title("书籍信息录入")
self.geometry(child_size)
title = tk.Label(self,text='书名:',bg=bg,font=bt_font)
title.grid(row=1,column=1,padx=30,pady=20)
author = tk.Label(self, text='作者:', bg=bg,
font=bt_font)
author.grid(row=2, column=1)
press = tk.Label(self, text='出版社:', bg=bg,
font=bt_font)
press.grid(row=3, column=1,pady=20)
category= tk.Label(self, text='类别:', bg=bg,
font=bt_font)
category.grid(row=4, column=1)
self.booktitle = ttk.Entry(self)
self.bookauthor = ttk.Entry(self)
self.bookpress = ttk.Entry(self)
self.booktitle.grid(row=1,column=2)
self.bookauthor.grid(row=2,column=2)
self.bookpress.grid(row=3,column=2)
self.sub = tk.Button(self,text='提交录入',font=bt_font,bg=bt_bg,command=self.commit)
self.sub.grid(row=5,column=2,pady=10)
# 设置条件下拉框
self.category_choice = tk.StringVar()
self.category_conditon = ttk.Combobox(self,
width=10,
textvariable=
self.category_choice)
self.category_conditon['values'] = ('小说','专业书','工具书','报告','其他')
self.category_conditon.grid(row=4,column=2, sticky=tk.W)
def commit(self):
title = self.booktitle.get()
author = self.bookauthor.get()
press = self.bookpress.get()
category = self.category_conditon.get()
if title=='' or author=='' or press=='' or category=='':
tkinter.messagebox.showinfo('提示', '信息不能为空!')
return None
self.cursor.execute(f'insert into books (title,author,press,category)values ("{title}","{author}","{press}","{category}")')
self.db.commit()
tkinter.messagebox.showinfo('提示','书籍信息添加成功!')
self.destroy()
def __del__(self):
self.db.close()
if __name__=='__main__':
Add().mainloop()
Python
1
https://gitee.com/daitianjun/booksystem.git
git@gitee.com:daitianjun/booksystem.git
daitianjun
booksystem
booksystem
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891