电影院售票系统可作为电影院网上售票平台,对于电影院的管理员,可以为该电影院引入添加新上映的电影,也可以对该电影院的电影进行排片,即安排播放时间、放映厅、票价、电影等等,也可以对用户的订单进行增加,删除,查找,修改操作。对于用户,可以进行注册,登录,查看排片信息、订单信息和购票功能。
import mysql.connector from tkinter import ttk import tkinter as tk import tkinter.font as tkFont from tkinter import * # 图形界面库 import tkinter.messagebox as messagebox import pymysql class beginpage : def __init__(self,p): p.destroy() self.window = tk.Tk() # 初始框的声明 self.window.title('电影院网上售票系统') self.window.geometry('600x600') # 这里的乘是小x self.window.geometry('+330+0') label = Label(self.window, text="电影院网上售票系统", font=("Verdana", 50),fg="red",bg='green') label.pack(pady=0) Button(self.window, text="电影院管理员登陆", font=tkFont.Font(size=20), command=lambda: adminpage(self.window), width=60, height=2,fg='white', bg='gray').pack() Button(self.window, text="用户登陆", font=tkFont.Font(size=20), command=lambda: UserPage(self.window), width=60, height=2, fg='white', bg='gray').pack() Button(self.window, text="用户注册", font=tkFont.Font(size=20), command=lambda: UserSign(self.window), width=60, height=2, fg='white', bg='gray').pack() Button(self.window, text='退出系统', height=2, font=tkFont.Font(size=20), width=60, command=self.window.destroy, fg='white', bg='gray').pack() self.window.mainloop() # 主消息循环 class adminpage : def __init__(self,p): p.destroy() self.window = tk.Tk() # 初始框的声明 self.window.title('管理员登录界面') self.window.geometry('600x600') # 这里的乘是小x self.window.geometry('+330+0') label = tk.Label(self.window, text='管理员登陆', bg='green', font=('Verdana', 30), width=40, height=3) label.pack() Label(self.window, text='管理员账号:', font=tkFont.Font(size=20)).pack(pady=25) self.admin_username = tk.Entry(self.window, width=30, font=tkFont.Font(size=20), bg='Ivory') self.admin_username.pack() Label(self.window, text='管理员密码:', font=tkFont.Font(size=20)).pack(pady=25) self.admin_pass = tk.Entry(self.window, width=30, font=tkFont.Font(size=20), bg='Ivory', show='*') self.admin_pass.pack() Button(self.window, text="登陆", width=10, font=tkFont.Font(size=15), command=self.login).pack(pady=40) self.window.protocol("WM_DELETE_WINDOW", self.back) self.window.mainloop() # 进入消息循环 def login(self): # 从界面获取的数据 print(str(self.admin_username.get())) print(str(self.admin_pass.get())) admin_pass = None # 数据库操作 查询管理员表 con = pymysql.connect(host='localhost', port=3306, user='root', passwd='112233', db='dyy', charset='utf8') # 打开数据库连接 cursor = con.cursor() # 使用cursor()方法获取操作游标 sql = "SELECT * FROM 管理员信息 WHERE 管理员账号 = '%s'" % (self.admin_username.get()) # SQL 查询语句 try: # 执行SQL语句 cursor.execute(sql) # 获取所有记录列表 results = cursor.fetchall() for row in results: admin_id = row[0] admin_pass = row[1] # 打印结果 print("admin_id=%s,admin_pass=%s" % (admin_id, admin_pass)) except: print("Error: unable to fecth data") messagebox.showinfo('警告!', '用户名或密码不正确!') con.close() # 关闭数据库连接 print("正在登陆管理员管理界面") # 从界面获取的数据 print("self", self.admin_pass) # 数据库里的数据 print("local", admin_pass) # 判断密码,正确则进入管理员操作界面 if self.admin_pass.get() == admin_pass: adminMessage(self.window) else: messagebox.showinfo('警告!', '用户名或密码不正确!') def back(self): beginpage(self.window) # 显示主窗口 销毁本窗口 class adminMessage: def __init__(self, parent_window): parent_window.update() parent_window.destroy() # 销毁子界面 self.window = tk.Tk() # 初始框的声明 self.window.title('首页') self.window.geometry('600x600') # 这里的乘是小 self.window.geometry('+330+0') label = Label(self.window, text="电影操作", font=("Verdana", 20)) label.pack(pady=50) # pady=100 界面的长度 Button(self.window, text="查看订单信息", font=tkFont.Font(size=30), command=lambda: adlook(self.window), width=30, height=2, fg='white', bg='gray', activebackground='black', activeforeground='white').pack() Button(self.window, text="查看电影信息", font=tkFont.Font(size=30), command=lambda: lookmovie(self.window), width=30, height=2, fg='white', bg='gray', activebackground='black', activeforeground='white').pack() Button(self.window, text="查看排片信息", font=tkFont.Font(size=30), command=lambda: adpai(self.window), width=30, height=2, fg='white', bg='gray', activebackground='black', activeforeground='white').pack() Button(self.window, text="退出登录", font=tkFont.Font(size=30), command=lambda: beginpage(self.window), width=30, height=2, fg='white', bg='gray', activebackground='black', activeforeground='white').pack() self.window.mainloop() # 主消息循环 class UserPage: def __init__(self, parent_window): parent_window.destroy() # 销毁主界面 self.window = tk.Tk() # 初始框的声明 self.window.title('用户登陆') self.window.geometry('600x600') # 这里的乘是小x self.window.geometry('+330+0') label = tk.Label(self.window, text='用户登陆', bg='green', font=('Verdana', 30), width=40, height=3) label.pack() Label(self.window, text='用户账号:', font=tkFont.Font(size=20)).pack(pady=25) self.user_id = tk.Entry(self.window, width=30, font=tkFont.Font(size=20), bg='Ivory') self.user_id.pack() Label(self.window, text='用户密码:', font=tkFont.Font(size=20)).pack(pady=25) self.user_pass = tk.Entry(self.window, width=30, font=tkFont.Font(size=20), bg='Ivory', show='*') self.user_pass.pack() Button(self.window, text="登陆", width=10, font=tkFont.Font(size=15), command=self.login).pack(pady=40) Button(self.window, text="返回", width=10, font=tkFont.Font(size=15), command=self.back).pack() self.window.protocol("WM_DELETE_WINDOW", self.back) # 捕捉右上角关闭点击 self.window.mainloop() # 进入消息循环 def login(self): print(str(self.user_id.get())) print(str(self.user_pass.get())) tou_pass = None # 数据库操作 查询管理员表 con = pymysql.connect(host='localhost', port=3306, user='root', passwd='112233', db='dyy', charset='utf8') # 打开数据库连接 cursor = con.cursor() # 使用cursor()方法获取操作游标 sql = "SELECT * FROM 用户信息 WHERE 用户账号 = '%s'" % (self.user_id.get()) # SQL 查询语句 try: # 执行SQL语句 cursor.execute(sql) # 获取所有记录列表 results = cursor.fetchall() for row in results: tou_id = row[0] tou_pass = row[4] idd=row[1] # 打印结果 print("tou_id=%s,tou_pass=%s" % (tou_id, tou_pass)) except: print("Error: unable to fecth data") messagebox.showinfo('警告!', '用户名或密码不正确!') con.close() # 关闭数据库连接 print("正在登陆.....") print("self", self.user_pass.get()) print("local", tou_pass) # 进入门票信息查看界面 if self.user_pass.get() == tou_pass: userindex(self.window) else: messagebox.showinfo('警告!', '用户名或密码不正确!') def back(self): beginpage(self.window) class userindex: def __init__(self, parent_window): parent_window.destroy() # 销毁主界面 self.window = tk.Tk() # 初始框的声明 self.window.title('首页') self.window.geometry('600x600') # 这里的乘是小x self.window.geometry('+330+0') label = tk.Label(self.window, text='欢迎光临豪大大电影院', bg='green', font=('Verdana', 30), width=40, height=3) label.pack() Button(self.window, text="查看全部排片", font=tkFont.Font(size=30), command=lambda: Showmovie(self.window), width=30, height=2, fg='white', bg='gray', activebackground='black', activeforeground='white').pack() Button(self.window, text="购票", font=tkFont.Font(size=30), command=lambda: Buy(self.window), width=30, height=2, fg='white', bg='gray', activebackground='black', activeforeground='white').pack() Button(self.window, text="查看订单", font=tkFont.Font(size=30), command=lambda: Look(self.window), width=30, height=2, fg='white', bg='gray', activebackground='black', activeforeground='white').pack() Button(self.window, text="退出登录", font=tkFont.Font(size=30), command=lambda: beginpage(self.window), width=30, height=2, fg='white', bg='gray', activebackground='black', activeforeground='white').pack() self.window.mainloop() # 主消息循环 class Showmovie: def __init__(self, parent_window): parent_window.destroy() # 自动销毁上一个界面 self.window = Tk() # 初始框的声明 self.window.title('管理员操作界面') self.window.geometry("600x600+300+0") # 初始窗口在屏幕中的位置 self.frame_center = tk.Frame(width=600, height=400) self.frame_bottom = tk.Frame(width=650, height=70) self.columns = ("排片编号", "电影名字", "放映厅", "放映时间", "价格") self.tree = ttk.Treeview(self.frame_center, show="headings", height=30, columns=self.columns) # 添加竖直滚动条 self.vbar = ttk.Scrollbar(self.frame_center, orient=VERTICAL, command=self.tree.yview) # 定义树形结构与滚动条 self.tree.configure(yscrollcommand=self.vbar.set) self.vbar.config(command=self.tree.yview()) # 定义id1为修改id时的暂存变量,这个是为了更新信息而设计的 self.id1 = 0 self.tree.column("排片编号", width=120, anchor='center') # 表示列,不显示 self.tree.column("电影名字", width=120, anchor='center') self.tree.column("放映厅", width=120, anchor='center') self.tree.column("放映时间", width=120, anchor='center') self.tree.column("价格", width=120, anchor='center') # grid方法将tree和vbar进行布局 self.tree.grid(row=0, column=0, sticky=NSEW) self.vbar.grid(row=0, column=1, sticky=NS) self.schedule_id=[] self.schedule_movie=[] self.hall_id=[] self.schedule_time=[] self.schedule_price=[] con = pymysql.connect(host='localhost', port=3306, user='root', passwd='112233', db='dyy', charset='utf8') cursor = con.cursor() # 使用cursor()方法获取操作游标 # sql = "SELECT * FROM 游客信息 WHERE 游客账号 = '%s'" % (self.var_identityid.get()) # SQL 查询语句 sql = "SELECT * FROM table_schedule" try: # 执行SQL语句 cursor.execute(sql) # 获取所有记录列表 results = cursor.fetchall() for row in results: self.schedule_id.append(row[0]) self.schedule_time.append(row[2]) self.schedule_price.append(row[1]) self.hall_id.append(row[4]) self.schedule_movie.append(row[5]) except: print("Error: unable to fetch data") messagebox.showinfo('警告!', '数据库连接失败!') con.close() # 关闭数据库连接 print("test***********************") for i in range(min(len(self.schedule_id), len(self.schedule_movie), len(self.hall_id), len(self.schedule_time), len(self.schedule_price))): # 写入数据 self.tree.insert('', i, values=( self.schedule_id[i], self.schedule_movie[i], self.hall_id[i], self.schedule_time[i], self.schedule_price[i])) for col in self.columns: # 绑定函数,使表头可排序 self.tree.heading(col, text=col, command=lambda _col=col: self.tree_sort_column(self.tree, _col, False)) #下方 self.var_schedule_id = StringVar() # 声明订票编号 self.var_movie_mane = StringVar() # 声明游客账号 self.var_hall_id = StringVar() # 声明身份证号 self.var_schedule_time = StringVar() # 声明联系电话 self.var_schedule_price = StringVar() # 声明订票数量 # 定义下方区域,查询功能块 self.chaxun = StringVar() self.right_bottom_gender_entry = Entry(self.frame_bottom, textvariable=self.chaxun, font=('Verdana', 15)) self.right_bottom_button = ttk.Button(self.frame_bottom, text='查询电影', width=20, command=self.put_data) self.right_bottom_button.grid(row=0, column=0, padx=20, pady=20) # 位置设置 self.right_bottom_gender_entry.grid(row=0, column=1) # 整体区域定位,利用了Frame和grid进行布局 self.frame_center.grid(row=0, column=0, columnspan=2, padx=4, pady=5) self.frame_bottom.grid(row=1, column=0, columnspan=2) # 设置固定组件,(0)就是将组件进行了固定 self.frame_center.grid_propagate(0) self.frame_bottom.grid_propagate(0) # 开始显示主菜单 self.frame_center.tkraise() # 开始显示主菜单 self.frame_bottom.tkraise() # 开始显示主菜单 self.window.protocol("WM_DELETE_WINDOW", self.back) # 捕捉右上角关闭点击,执行back方法 self.window.mainloop() # 进入消息循环 def put_data(self): self.delButton() print(self.chaxun.get()) # 输入框内的内容 # 打开数据库连接,准备查找指定的信息 # 再次进行初始化,进行首行数据的插入 con =