Python3.7结合sqlite3开发GUI小程序

一、概述
   本系统可对员工信息、菜单信息等用户所需要的信息进行数据获取和展示,根据用户的需求及其所提供的数据,将各类信息传入数据库进行存储。系统可根据用户的权限进行信息的展示,如管理员可对数据进行增删改查满足管理需求,员工登录后只可对部分信息进行查看,满足了不同用户的需求。

二、登录窗设计

from tkinter import messagebox
import sqlite3
from tkinter import *
from tkinter.ttk import *
import 操作界面
import 操作界面员工


class Title:
    def __init__(self, master):
        self.root = master
        self.root.geometry('580x500+250+100')
        self.root.resizable(False, False)
        self.root.iconbitmap("图标1.ico")
        self.root.title('餐厅信息管理系统1.0')
        self.root["background"] = "#E1C4C4"
        label1 = Label(self.root, foreground="#FF8080", font=("楷体", 30, "bold"), text='欢迎使用餐厅信息管理系统',
                   anchor='center',  # 指定文本(text)或图像(bitmap/image)在Label中的显示位置(方位)
                   justify='center')  # 多行对齐# tkinter.Label,对象,类型
        label1.pack()  # 显示
        self.root.pic = PhotoImage(file='cantu.gif')
        Label(image=self.root.pic).pack(pady=10)
class LoginPage:
    """登录界面"""
    def __init__(self, master):
        self.root = master
        self.root.geometry('580x500')
        self.root.iconbitmap("图标1.ico")
        self.root.title('餐厅信息管理系统1.0')
        self.root["background"] = "#E1C4C4"
         # 显示 pady垂直方向的外边距
        self.conn = sqlite3.connect('test.db')
        self.username = StringVar()
        self.password = StringVar()
        self.power = StringVar()
        self.power.set('1')
        self.page = Frame(self.root)
        self.creatapage()
        Frame(self.root).destroy()

    def creatapage(self):
        """界面布局"""

        self.Style01 = Style()
        self.Style01.configure("TPanedwindow", background="#E1C4C4")
        self.Style01.configure("TButton", width=10, font=("楷体", 15, "bold"),background="#E1C4C4",foreground = "#FF8080",)

        Label(self.page).grid(row=0)
        Label(self.page,font=('楷体',14,"bold"), foreground = "#FF8080",text='用户名:').grid(row=1, stick=W, pady=10)
        Entry(self.page,font=('楷体',14,"bold"),width=13, foreground = "#FF8080", textvariable=self.username).grid(row=1, column=1, stick=E)
        Label(self.page,font=('楷体',14,"bold"), foreground = "#FF8080", text='密码:').grid(row=2, stick=W, pady=10)
        Entry(self.page, font=('楷体',14,"bold"),width=13, foreground = "#FF8080",textvariable=self.password, show='*').grid(row=2, stick=E, column=1)
        Label(self.page, font=('楷体',14,"bold"), foreground = "#FF8080",text='权限:').grid(row=3, stick=W, pady=10)
        self.power.set("1")
        radio=Radiobutton(self.page,text='员工',variable=self.power,value='员工')
        radio.grid(row = 3,stick=W,column=1)
        radio=Radiobutton(self.page,text='管理员',variable=self.power,value='管理员')
        radio.grid(row = 3,stick=W,column=2)
        #row行,column列的位置
        Button(self.page, text='登录', command=self.login).grid(row=4, stick=W, pady=10)
        Button(self.page, text='注册账号', command=self.register).grid(row=4, stick=E, column=1)
        self.page.pack()
    def login(self):
        """登录功能"""
        curs = self.conn.cursor()
        query = "select username, pwd, power from user where username='%s'" % self.username.get()
        curs.execute(query)  # 返回一个迭代器
        c = curs.fetchall()  # 接收全部信息
        if len(c) == 0:
            messagebox.showerror('登录失败', '账户不存在')
        else:
            us,pw,pow=c[0]
            if us == self.username.get() and pw == self.password.get() and pow == self.power.get():
                  self.conn.close()
                  messagebox.showinfo('登录成功', '欢迎:%s' % us)
                  self.load_main()
            else:
                messagebox.showwarning('登录失败', '密码或权限错误')
    def load_main(self):
        self.page.destroy()

        if self.power.get()=='管理员':
            self.page.destroy()
            操作界面.operation(self.root)
        else:
            self.page.destroy()
            操作界面员工.operation(self.root)

    def register(self):
        """注册功能跳转"""
        self.conn.close()
        self.page.destroy()
        RegisterPage(self.root)


class RegisterPage:
    """注册界面"""

    def __init__(self, master=None):
        self.root = master
        self.root.title('账号注册')
        self.root.geometry('580x550')
        self.conn = sqlite3.connect('test.db')
        self.username = StringVar()
        self.password0 = StringVar()  # 第一次输入密码
        self.password1 = StringVar()  # 第二次输入密码
        self.power = StringVar()
        self.power.set('1')
        self.page = Frame(self.root)
        self.createpage()

    def createpage(self):
        """界面布局"""
        # Label(self.page).grid(row=0)

        Label(self.page, font=('楷体',14,"bold"), foreground = "#FF8080",text="账号:").grid(row=1, stick=W, pady=10)
        Entry(self.page, font=('楷体',14,"bold"),width=13, foreground = "#FF8080",textvariable=self.username).grid(row=1, column=1, stick=E)
        Label(self.page, font=('楷体',14,"bold"), foreground = "#FF8080",text="密码:").grid(row=2, stick=W, pady=10)
        Entry(self.page, font=('楷体',14,"bold"),textvariable=self.password0,width=13, foreground = "#FF8080",show='*').grid(row=2, column=1, stick=E)
        Label(self.page, font=('楷体',14,"bold"), foreground = "#FF8080",text="再次输入:").grid(row=3, stick=W, pady=10)
        Entry(self.page, font=('楷体',14,"bold"),textvariable=self.password1,width=13, foreground = "#FF8080", show='*').grid(row=3, column=1, stick=E)
        Label(self.page, font=('楷体',14,"bold"), foreground = "#FF8080",text='权限:').grid(row=4, stick=W, pady=10)
        Radiobutton(self.page, text='员工', variable=self.power, value='员工').grid(row=4, stick=W, column=1)
        Radiobutton(self.page, text='管理员', variable=self.power, value='管理员').grid(row=4, stick=W, column=2)
        Button(self.page, text="返回", command=self.repage).grid(row=5, stick=W, pady=10)
        Button(self.page, text="注册", command=self.register).grid(row=5, column=1, stick=E)
        self.page.pack()

    def repage(self):
        """返回登录界面"""
        self.page.destroy()#关闭视窗
        self.conn.close()
        LoginPage(self.root)

    def register(self):
        """注册"""
        if self.password0.get() != self.password1.get():
            messagebox.showwarning('错误', '密码核对错误')
        elif len(self.username.get()) == 0 or len(self.password0.get()) == 0 :
            messagebox.showerror("错误", "不能为空")
        else:
            curs = self.conn.cursor()
            query = 'insert into user values (?,?,?)'
            val = [self.username.get(), self.password0.get(),self.power.get()]
            try:
                curs.execute(query, val)
                self.conn.commit()
                self.conn.close()
                messagebox.showinfo("成功", "注册成功,按确定返回登录界面")
                self.page.destroy()
                LoginPage(self.root)

            except sqlite3.IntegrityError:
                messagebox.showerror("注册失败", "该账户已存在")

    def load_main(self):
        # 关闭当前窗体
        self.conn.commit()
        self.conn.close()
        self.page.destroy()
        LoginPage(self.root)

if __name__ == '__main__':
    root = Tk()
    Title(root)
    LoginPage(root)
    root.mainloop()

三、操作菜单栏

import sqlite3
from tkinter import *
from tkinter import messagebox
from tkinter.ttk import *
import 菜单界面
import 操作员工
import 部门人员查询
import 厨师菜色查询


class operation:
    """操作界面"""

    def __init__(self,master):
        super().__init__()
        self.root = master
        self.root.geometry('480x400')
        #self.root.resizable(False, False)
        self.root["background"] = "#E1C4C4"
        self.root.iconbitmap("图标1.ico")
        self.root.title('管理员界面')
        self.conn = sqlite3.connect('test.db')
        self.username = StringVar()
        self.password = StringVar()
        self.power = StringVar()

        self.creatapage()
       
    def creatapage(self):
        """界面布局"""
        # 设定Style
        self.Style01 = Style()

        self.Style01.configure("TButton", width=15 ,  background = "#E1C4C4",foreground = "#FF8080",font=("华文黑体", 15, "bold"))
 
        # 左边:按钮区域,创建一个容器
        self.Pane_root = PanedWindow(width=590, height=500, style="root.TPanedwindow")
        self.Pane_root.place(x=0)

        # 添加按钮
        self.Button1 = Button(self.Pane_root, text="操作菜单", style="TButton",command=self.view2)
        self.Button1.place(x=170, y=40)
        self.Button4 = Button(self.Pane_root, text="操作员工", style="TButton",command=self.view3)
        self.Button4.place(x=170, y=100)

        self.Button2 = Button(self.Pane_root, text="部门人员查询", style="TButton",
                              command=self.view1)
        self.Button2.place(x=170, y=220)
        self.Button3 = Button(self.Pane_root, text="厨师菜色查询", style="TButton",
                              command=self.view4)
        self.Button3.place(x=170, y=160)
        self.Button5 = Button(self.Pane_root, text="退出系统", style="TButton",
                              command=self.view5)
        self.Button5.place(x=170, y=280)



    def 
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
### 回答1: 要在Jetson Nano上安装Python 3.7,您可以按照以下步骤操作: 1. 打开终端并更新软件包列表: sudo apt-get update 2. 安装依赖项: sudo apt-get install libssl-dev openssl libsqlite3-dev sqlite3 libbz2-dev libreadline-dev libncurses5-dev libncursesw5-dev libffi-dev liblzma-dev 3. 下载Python 3.7源代码: wget https://www.python.org/ftp/python/3.7./Python-3.7..tar.xz 4. 解压缩源代码: tar -xf Python-3.7..tar.xz 5. 进入解压缩后的目录: cd Python-3.7. 6. 配置安装选项: ./configure --enable-optimizations 7. 编译并安装Python 3.7: make -j4 sudo make altinstall 8. 确认Python 3.7已安装: python3.7 --version 现在您已经成功地在Jetson Nano上安装了Python 3.7。 ### 回答2: Jetson Nano是一个嵌入式系统,它提供了一个方便快捷的方式来实现各种AI应用。Python 3.7是一个非常流行的编程语言和版本,同时这个版本也提供了许多新的功能。为了在Jetson Nano上安装Python 3.7,您可以选择使用Anaconda或者手动安装。 一种选择是在Jetson Nano上安装Anaconda。这是一种现成的Python发行版,其中包含Python 3.7和许多有用的库。要安装Anaconda,您可以按照以下步骤进行操作: 1. 在Jetson Nano上下载Anaconda发行版(例如Miniconda)。 2. 执行以下命令:chmod +x Miniconda3-latest-Linux-aarch64.sh,使安装程序可执行。 3. 运行以下命令来安装Anaconda:./Miniconda3-latest-Linux-aarch64.sh。 4. 安装完成后,在终端中使用conda install命令安装您所需要的Python库。 另一种选择是在Jetson Nano上手动安装Python 3.7。为此,您可以按照以下步骤操作: 1. 从Python官网下载Python 3.7源代码。 2. 解压缩源代码:tar xvf Python-3.7.10.tgz。 3. 进入解压缩的目录:cd Python-3.7.10。 4. 执行以下命令以配置Python的安装:./configure --enable-shared --prefix=/usr/local LDFLAGS="-Wl,--rpath=/usr/local/lib". 5. 执行以下命令以编译Python:make -j4。 6. 执行以下命令以安装Python:sudo make install。 7. 安装完成后,在终端中使用pip3 install命令安装您所需要的Python库。 需要注意的是,在安装Python 3.7之前,您需要确保Jetson Nano上已经安装了基本的编译器工具链(例如build-essential、libc6-dev、libssl-dev和libffi-dev)。如果您安装了Anaconda,则会自动安装所需的工具链。而如果您手动安装Python 3.7,则需要首先安装这些工具链。 ### 回答3: Jetson Nano 是 NVIDIA 推出的一款小型 AI 计算机,能够提供高度优化的硬件和软件支持,以便于进行 AI 开发。对于 AI 开发者来说,Python 是一个必不可少的编程语言。安装 Python3.7 可以为开发者提供更好的编程环境。以下是安装 Jetson Nano 上 Python3.7 的步骤: 1. 更新系统:在终端输入 sudo apt-get update && sudo apt-get upgrade,升级系统。 2. 安装依赖包:输入 sudo apt-get install libffi-dev libssl-dev libsqlite3-dev libreadline-dev,安装 Python3.7 的必要依赖项。 3. 下载 Python3.7:在 Python 官网下载 Python3.7 的 tar 包。需要在 Jetson Nano 终端用 wget 命令下载。下载后,将文件解压到目标文件夹下。可使用以下命令完成: tar -zxvf Python-3.7.9.tar.gz cd Python-3.7.9 4. 配置安装:准备安装 Python3.7。使用以下命令: ./configure --enable-optimizations 5. 安装 Python3.7:使用以下命令进行安装: make -j4 sudo make altinstall -j4 表示可以并行处理代码,请根据 Jetson Nano 的实际处理器性能进行调整。 6. 安装完成:使用以下命令测试 Python3.7 是否成功安装: python3.7 --version 如果安装成功,将会返回 Python3.7 的版本号。 以上就是安装 Jetson Nano 上 Python3.7 的详细步骤。有关 Python3.7 在 Jetson Nano 上的应用,请参考 Jetson AI Fundamentals 等相关文档,了解更多细节。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

H_IT

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值