当前位置:   article > 正文

基于mysql+python tkinter实现电影院售票系统_数据库实践作业网上订票系统(python可视化界面)

数据库实践作业网上订票系统(python可视化界面)

电影院售票系统可作为电影院网上售票平台,对于电影院的管理员,可以为该电影院引入添加新上映的电影,也可以对该电影院的电影进行排片,即安排播放时间、放映厅、票价、电影等等,也可以对用户的订单进行增加,删除,查找,修改操作。对于用户,可以进行注册,登录,查看排片信息、订单信息和购票功能。

  1. import mysql.connector
  2. from tkinter import ttk
  3. import tkinter as tk
  4. import tkinter.font as tkFont
  5. from tkinter import * # 图形界面库
  6. import tkinter.messagebox as messagebox
  7. import pymysql
  8. class beginpage :
  9. def __init__(self,p):
  10. p.destroy()
  11. self.window = tk.Tk() # 初始框的声明
  12. self.window.title('电影院网上售票系统')
  13. self.window.geometry('600x600') # 这里的乘是小x
  14. self.window.geometry('+330+0')
  15. label = Label(self.window, text="电影院网上售票系统", font=("Verdana", 50),fg="red",bg='green')
  16. label.pack(pady=0)
  17. Button(self.window, text="电影院管理员登陆", font=tkFont.Font(size=20), command=lambda: adminpage(self.window), width=60,
  18. height=2,fg='white', bg='gray').pack()
  19. Button(self.window, text="用户登陆", font=tkFont.Font(size=20), command=lambda: UserPage(self.window), width=60,
  20. height=2, fg='white', bg='gray').pack()
  21. Button(self.window, text="用户注册", font=tkFont.Font(size=20), command=lambda: UserSign(self.window), width=60,
  22. height=2, fg='white', bg='gray').pack()
  23. Button(self.window, text='退出系统', height=2, font=tkFont.Font(size=20), width=60, command=self.window.destroy,
  24. fg='white', bg='gray').pack()
  25. self.window.mainloop() # 主消息循环
  26. class adminpage :
  27. def __init__(self,p):
  28. p.destroy()
  29. self.window = tk.Tk() # 初始框的声明
  30. self.window.title('管理员登录界面')
  31. self.window.geometry('600x600') # 这里的乘是小x
  32. self.window.geometry('+330+0')
  33. label = tk.Label(self.window, text='管理员登陆', bg='green', font=('Verdana', 30), width=40, height=3)
  34. label.pack()
  35. Label(self.window, text='管理员账号:', font=tkFont.Font(size=20)).pack(pady=25)
  36. self.admin_username = tk.Entry(self.window, width=30, font=tkFont.Font(size=20), bg='Ivory')
  37. self.admin_username.pack()
  38. Label(self.window, text='管理员密码:', font=tkFont.Font(size=20)).pack(pady=25)
  39. self.admin_pass = tk.Entry(self.window, width=30, font=tkFont.Font(size=20), bg='Ivory', show='*')
  40. self.admin_pass.pack()
  41. Button(self.window, text="登陆", width=10, font=tkFont.Font(size=15), command=self.login).pack(pady=40)
  42. self.window.protocol("WM_DELETE_WINDOW", self.back)
  43. self.window.mainloop() # 进入消息循环
  44. def login(self):
  45. # 从界面获取的数据
  46. print(str(self.admin_username.get()))
  47. print(str(self.admin_pass.get()))
  48. admin_pass = None
  49. # 数据库操作 查询管理员表
  50. con = pymysql.connect(host='localhost', port=3306, user='root', passwd='112233', db='dyy',
  51. charset='utf8') # 打开数据库连接
  52. cursor = con.cursor() # 使用cursor()方法获取操作游标
  53. sql = "SELECT * FROM 管理员信息 WHERE 管理员账号 = '%s'" % (self.admin_username.get()) # SQL 查询语句
  54. try:
  55. # 执行SQL语句
  56. cursor.execute(sql)
  57. # 获取所有记录列表
  58. results = cursor.fetchall()
  59. for row in results:
  60. admin_id = row[0]
  61. admin_pass = row[1]
  62. # 打印结果
  63. print("admin_id=%s,admin_pass=%s" % (admin_id, admin_pass))
  64. except:
  65. print("Error: unable to fecth data")
  66. messagebox.showinfo('警告!', '用户名或密码不正确!')
  67. con.close() # 关闭数据库连接
  68. print("正在登陆管理员管理界面")
  69. # 从界面获取的数据
  70. print("self", self.admin_pass)
  71. # 数据库里的数据
  72. print("local", admin_pass)
  73. # 判断密码,正确则进入管理员操作界面
  74. if self.admin_pass.get() == admin_pass:
  75. adminMessage(self.window)
  76. else:
  77. messagebox.showinfo('警告!', '用户名或密码不正确!')
  78. def back(self):
  79. beginpage(self.window) # 显示主窗口 销毁本窗口
  80. class adminMessage:
  81. def __init__(self, parent_window):
  82. parent_window.update()
  83. parent_window.destroy() # 销毁子界面
  84. self.window = tk.Tk() # 初始框的声明
  85. self.window.title('首页')
  86. self.window.geometry('600x600') # 这里的乘是小
  87. self.window.geometry('+330+0')
  88. label = Label(self.window, text="电影操作", font=("Verdana", 20))
  89. label.pack(pady=50) # pady=100 界面的长度
  90. Button(self.window, text="查看订单信息", font=tkFont.Font(size=30), command=lambda: adlook(self.window), width=30,
  91. height=2,
  92. fg='white', bg='gray', activebackground='black', activeforeground='white').pack()
  93. Button(self.window, text="查看电影信息", font=tkFont.Font(size=30), command=lambda: lookmovie(self.window), width=30,
  94. height=2, fg='white', bg='gray', activebackground='black', activeforeground='white').pack()
  95. Button(self.window, text="查看排片信息", font=tkFont.Font(size=30), command=lambda: adpai(self.window), width=30,
  96. height=2, fg='white', bg='gray', activebackground='black', activeforeground='white').pack()
  97. Button(self.window, text="退出登录", font=tkFont.Font(size=30), command=lambda: beginpage(self.window), width=30,
  98. height=2, fg='white', bg='gray', activebackground='black', activeforeground='white').pack()
  99. self.window.mainloop() # 主消息循环
  100. class UserPage:
  101. def __init__(self, parent_window):
  102. parent_window.destroy() # 销毁主界面
  103. self.window = tk.Tk() # 初始框的声明
  104. self.window.title('用户登陆')
  105. self.window.geometry('600x600') # 这里的乘是小x
  106. self.window.geometry('+330+0')
  107. label = tk.Label(self.window, text='用户登陆', bg='green', font=('Verdana', 30), width=40, height=3)
  108. label.pack()
  109. Label(self.window, text='用户账号:', font=tkFont.Font(size=20)).pack(pady=25)
  110. self.user_id = tk.Entry(self.window, width=30, font=tkFont.Font(size=20), bg='Ivory')
  111. self.user_id.pack()
  112. Label(self.window, text='用户密码:', font=tkFont.Font(size=20)).pack(pady=25)
  113. self.user_pass = tk.Entry(self.window, width=30, font=tkFont.Font(size=20), bg='Ivory', show='*')
  114. self.user_pass.pack()
  115. Button(self.window, text="登陆", width=10, font=tkFont.Font(size=15), command=self.login).pack(pady=40)
  116. Button(self.window, text="返回", width=10, font=tkFont.Font(size=15), command=self.back).pack()
  117. self.window.protocol("WM_DELETE_WINDOW", self.back) # 捕捉右上角关闭点击
  118. self.window.mainloop() # 进入消息循环
  119. def login(self):
  120. print(str(self.user_id.get()))
  121. print(str(self.user_pass.get()))
  122. tou_pass = None
  123. # 数据库操作 查询管理员表
  124. con = pymysql.connect(host='localhost', port=3306, user='root', passwd='112233', db='dyy',
  125. charset='utf8') # 打开数据库连接
  126. cursor = con.cursor() # 使用cursor()方法获取操作游标
  127. sql = "SELECT * FROM 用户信息 WHERE 用户账号 = '%s'" % (self.user_id.get()) # SQL 查询语句
  128. try:
  129. # 执行SQL语句
  130. cursor.execute(sql)
  131. # 获取所有记录列表
  132. results = cursor.fetchall()
  133. for row in results:
  134. tou_id = row[0]
  135. tou_pass = row[4]
  136. idd=row[1]
  137. # 打印结果
  138. print("tou_id=%s,tou_pass=%s" % (tou_id, tou_pass))
  139. except:
  140. print("Error: unable to fecth data")
  141. messagebox.showinfo('警告!', '用户名或密码不正确!')
  142. con.close() # 关闭数据库连接
  143. print("正在登陆.....")
  144. print("self", self.user_pass.get())
  145. print("local", tou_pass)
  146. # 进入门票信息查看界面
  147. if self.user_pass.get() == tou_pass:
  148. userindex(self.window)
  149. else:
  150. messagebox.showinfo('警告!', '用户名或密码不正确!')
  151. def back(self):
  152. beginpage(self.window)
  153. class userindex:
  154. def __init__(self, parent_window):
  155. parent_window.destroy() # 销毁主界面
  156. self.window = tk.Tk() # 初始框的声明
  157. self.window.title('首页')
  158. self.window.geometry('600x600') # 这里的乘是小x
  159. self.window.geometry('+330+0')
  160. label = tk.Label(self.window, text='欢迎光临豪大大电影院', bg='green', font=('Verdana', 30), width=40, height=3)
  161. label.pack()
  162. Button(self.window, text="查看全部排片", font=tkFont.Font(size=30), command=lambda: Showmovie(self.window), width=30,
  163. height=2,
  164. fg='white', bg='gray', activebackground='black', activeforeground='white').pack()
  165. Button(self.window, text="购票", font=tkFont.Font(size=30), command=lambda: Buy(self.window),
  166. width=30,
  167. height=2, fg='white', bg='gray', activebackground='black', activeforeground='white').pack()
  168. Button(self.window, text="查看订单", font=tkFont.Font(size=30), command=lambda: Look(self.window), width=30,
  169. height=2, fg='white', bg='gray', activebackground='black', activeforeground='white').pack()
  170. Button(self.window, text="退出登录", font=tkFont.Font(size=30), command=lambda: beginpage(self.window), width=30,
  171. height=2, fg='white', bg='gray', activebackground='black', activeforeground='white').pack()
  172. self.window.mainloop() # 主消息循环
  173. class Showmovie:
  174. def __init__(self, parent_window):
  175. parent_window.destroy() # 自动销毁上一个界面
  176. self.window = Tk() # 初始框的声明
  177. self.window.title('管理员操作界面')
  178. self.window.geometry("600x600+300+0") # 初始窗口在屏幕中的位置
  179. self.frame_center = tk.Frame(width=600, height=400)
  180. self.frame_bottom = tk.Frame(width=650, height=70)
  181. self.columns = ("排片编号", "电影名字", "放映厅", "放映时间", "价格")
  182. self.tree = ttk.Treeview(self.frame_center, show="headings", height=30, columns=self.columns)
  183. # 添加竖直滚动条
  184. self.vbar = ttk.Scrollbar(self.frame_center, orient=VERTICAL, command=self.tree.yview)
  185. # 定义树形结构与滚动条
  186. self.tree.configure(yscrollcommand=self.vbar.set)
  187. self.vbar.config(command=self.tree.yview())
  188. # 定义id1为修改id时的暂存变量,这个是为了更新信息而设计的
  189. self.id1 = 0
  190. self.tree.column("排片编号", width=120, anchor='center') # 表示列,不显示
  191. self.tree.column("电影名字", width=120, anchor='center')
  192. self.tree.column("放映厅", width=120, anchor='center')
  193. self.tree.column("放映时间", width=120, anchor='center')
  194. self.tree.column("价格", width=120, anchor='center')
  195. # grid方法将tree和vbar进行布局
  196. self.tree.grid(row=0, column=0, sticky=NSEW)
  197. self.vbar.grid(row=0, column=1, sticky=NS)
  198. self.schedule_id=[]
  199. self.schedule_movie=[]
  200. self.hall_id=[]
  201. self.schedule_time=[]
  202. self.schedule_price=[]
  203. con = pymysql.connect(host='localhost', port=3306, user='root', passwd='112233', db='dyy', charset='utf8')
  204. cursor = con.cursor() # 使用cursor()方法获取操作游标
  205. # sql = "SELECT * FROM 游客信息 WHERE 游客账号 = '%s'" % (self.var_identityid.get()) # SQL 查询语句
  206. sql = "SELECT * FROM table_schedule"
  207. try:
  208. # 执行SQL语句
  209. cursor.execute(sql)
  210. # 获取所有记录列表
  211. results = cursor.fetchall()
  212. for row in results:
  213. self.schedule_id.append(row[0])
  214. self.schedule_time.append(row[2])
  215. self.schedule_price.append(row[1])
  216. self.hall_id.append(row[4])
  217. self.schedule_movie.append(row[5])
  218. except:
  219. print("Error: unable to fetch data")
  220. messagebox.showinfo('警告!', '数据库连接失败!')
  221. con.close() # 关闭数据库连接
  222. print("test***********************")
  223. 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))): # 写入数据
  224. self.tree.insert('', i, values=(
  225. self.schedule_id[i], self.schedule_movie[i], self.hall_id[i], self.schedule_time[i], self.schedule_price[i]))
  226. for col in self.columns: # 绑定函数,使表头可排序
  227. self.tree.heading(col, text=col, command=lambda _col=col: self.tree_sort_column(self.tree, _col, False))
  228. #下方
  229. self.var_schedule_id = StringVar() # 声明订票编号
  230. self.var_movie_mane = StringVar() # 声明游客账号
  231. self.var_hall_id = StringVar() # 声明身份证号
  232. self.var_schedule_time = StringVar() # 声明联系电话
  233. self.var_schedule_price = StringVar() # 声明订票数量
  234. # 定义下方区域,查询功能块
  235. self.chaxun = StringVar()
  236. self.right_bottom_gender_entry = Entry(self.frame_bottom, textvariable=self.chaxun, font=('Verdana', 15))
  237. self.right_bottom_button = ttk.Button(self.frame_bottom, text='查询电影', width=20, command=self.put_data)
  238. self.right_bottom_button.grid(row=0, column=0, padx=20, pady=20) # 位置设置
  239. self.right_bottom_gender_entry.grid(row=0, column=1)
  240. # 整体区域定位,利用了Frame和grid进行布局
  241. self.frame_center.grid(row=0, column=0, columnspan=2, padx=4, pady=5)
  242. self.frame_bottom.grid(row=1, column=0, columnspan=2)
  243. # 设置固定组件,(0)就是将组件进行了固定
  244. self.frame_center.grid_propagate(0)
  245. self.frame_bottom.grid_propagate(0)
  246. # 开始显示主菜单
  247. self.frame_center.tkraise() # 开始显示主菜单
  248. self.frame_bottom.tkraise() # 开始显示主菜单
  249. self.window.protocol("WM_DELETE_WINDOW", self.back) # 捕捉右上角关闭点击,执行back方法
  250. self.window.mainloop() # 进入消息循环
  251. def put_data(self):
  252. self.delButton()
  253. print(self.chaxun.get()) # 输入框内的内容
  254. # 打开数据库连接,准备查找指定的信息
  255. # 再次进行初始化,进行首行数据的插入
  256. con = pymysql.connect(host='localhost', port=3306, user='root', passwd='112233', db='dyy', charset='utf8')
  257. cursor = con.cursor() # 使用cursor()方法获取操作游标
  258. # sql = "use EMIS exec proc_cha '%s'" % (self.chaxun.get())
  259. sql = "SELECT * FROM table_schedule WHERE schedule_movie = '%s' " % (self.chaxun.get())
  260. try:
  261. # 执行SQL语句2
  262. cursor.execute(sql)
  263. # 获取所有记录列表
  264. results = cursor.fetchall()
  265. self.schedule_id = [] # 订票编号
  266. self.schedule_movie = [] # 游客账号
  267. self.hall_id = [] # 身份证号
  268. self.schedule_time = [] # 联系电话
  269. self.schedule_price = [] # 订票数量
  270. for row in results:
  271. self.schedule_id.append(row[0])
  272. self.schedule_time.append(row[2])
  273. self.schedule_price.append(row[1])
  274. self.hall_id.append(row[4])
  275. self.schedule_movie.append(row[5])
  276. except:
  277. print("Error: unable to fetch data")
  278. messagebox.showinfo('警告!', '数据库连接失败!')
  279. con.close() # 关闭数据库连接
  280. print("进行数据的插入")
  281. 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))): # 写入数据
  282. self.tree.insert('', i, values=(
  283. self.schedule_id[i], self.schedule_movie[i], self.hall_id[i], self.schedule_time[i], self.schedule_price[i]))
  284. for col in self.columns: # 绑定函数,使表头可排序
  285. self.tree.heading(col, text=col, command=lambda _col=col: self.tree_sort_column(self.tree, _col, False))
  286. def delButton(self):
  287. x = self.tree.get_children()
  288. for item in x:
  289. self.tree.delete(item)
  290. def tree_sort_column(self, tv, col, reverse): # Treeview、列名、排列方式
  291. l = [(tv.set(k, col), k) for k in tv.get_children('')]
  292. l.sort(reverse=reverse) # 排序方式
  293. for index, (val, k) in enumerate(l): # 根据排序后索引移动
  294. tv.move(k, '', index)
  295. tv.heading(col, command=lambda: self.tree_sort_column(tv, col, not reverse)) # 重写标题,使之成为再点倒序的标题
  296. def back(self):
  297. userindex(self.window)
  298. class Buy:
  299. def __init__(self, parent_window):
  300. parent_window.destroy() # 销毁主界面
  301. self.window = tk.Tk() # 初始框的声明
  302. self.window.title('购票')
  303. self.window.geometry('600x700') # 这里的乘是小x
  304. self.window.geometry('+330+0')
  305. label = tk.Label(self.window, text='购票', bg='green', font=('Verdana', 20), width=40, height=3)
  306. label.pack()
  307. Label(self.window, text='取票号:', font=tkFont.Font(size=15)).pack(pady=25)
  308. self.userbuy_id = tk.Entry(self.window, width=30, font=tkFont.Font(size=15), bg='Ivory')
  309. self.userbuy_id.pack()
  310. Label(self.window, text='用户编号:', font=tkFont.Font(size=15)).pack(pady=25)
  311. self.user_id = tk.Entry(self.window, width=30, font=tkFont.Font(size=15), bg='Ivory')
  312. self.user_id.pack()
  313. Label(self.window, text='排片编号:', font=tkFont.Font(size=15)).pack(pady=25)
  314. self.schedule_id = tk.Entry(self.window, width=30, font=tkFont.Font(size=15), bg='Ivory')
  315. self.schedule_id.pack()
  316. Label(self.window, text='座位号:', font=tkFont.Font(size=15)).pack(pady=25)
  317. self.seat_id = tk.Entry(self.window, width=30, font=tkFont.Font(size=15), bg='Ivory')
  318. self.seat_id.pack()
  319. Button(self.window, text="购买", width=10, font=tkFont.Font(size=15), command=self.login).pack(pady=40)
  320. Button(self.window, text="返回", width=10, font=tkFont.Font(size=15), command=self.back).pack()
  321. self.window.protocol("WM_DELETE_WINDOW", self.back) # 捕捉右上角关闭点击
  322. self.window.mainloop() # 进入消息循环
  323. def login(self):
  324. print(str(self.schedule_id.get()))
  325. print(str(self.seat_id.get()))
  326. tou_pass = None
  327. # 数据库操作 查询管理员表
  328. con = pymysql.connect(host='localhost', port=3306, user='root', passwd='112233', db='dyy',
  329. charset='utf8') # 打开数据库连接
  330. cursor = con.cursor() # 使用cursor()方法获取操作游标
  331. sql = "SELECT hall_id FROM table_schedule WHERE schedule_id = '%s'" % (self.schedule_id.get()) # SQL 查询语句
  332. try:
  333. # 执行SQL语句
  334. cursor.execute(sql)
  335. # 获取所有记录列表
  336. results = cursor.fetchall()
  337. print(results)
  338. for row in results:
  339. self.hall_id = row[0]
  340. # 打印结果
  341. print("tou_id=%s" % (self.hall_id))
  342. except:
  343. print("Error: unable to fecth data")
  344. messagebox.showinfo('警告!', '用户名!')
  345. con.close() # 关闭数据库连接
  346. con = pymysql.connect(host='localhost', port=3306, user='root', passwd='112233', db='dyy',
  347. charset='utf8') # 打开数据库连接
  348. cursor = con.cursor() # 使用cursor()方法获取操作游标
  349. sql1 = "SELECT hall_sets FROM table_hall WHERE hall_id = '%s'" % (self.hall_id)
  350. try:
  351. # 执行SQL语句
  352. cursor.execute(sql1)
  353. # 获取所有记录列表
  354. results = cursor.fetchall()
  355. for row in results:
  356. hall_seats = row[0]
  357. print(hall_seats)
  358. except:
  359. print("Error: unable to fecth data")
  360. messagebox.showinfo('警告!')
  361. con.close() # 关闭数据库连接
  362. con = pymysql.connect(host='localhost', port=3306, user='root', passwd='112233', db='dyy',
  363. charset='utf8') # 打开数据库连接
  364. cursor = con.cursor() # 使用cursor()方法获取操作游标
  365. sql1 = "INSERT INTO table_userbuy(userbuy_id,schedule_id,user_id,set_id) \
  366. VALUES ('%s', '%s', '%s', '%s')" % \
  367. (self.userbuy_id.get(), self.schedule_id.get(), self.user_id.get(), self.seat_id.get()) # SQL 插入语句
  368. try:
  369. cursor.execute(sql1) # 执行sql语句
  370. print("yes")
  371. con.commit() # 提交到数据库执行
  372. except:
  373. con.rollback() # 发生错误时回滚
  374. messagebox.showinfo('警告!', '数据库连接失败!')
  375. con.close() # 关闭数据库连接
  376. # 购买结果
  377. if float(self.seat_id.get())<float(hall_seats):
  378. messagebox.showinfo('购买成功!')
  379. else:
  380. messagebox.showinfo('没有该座位号!')
  381. def back(self):
  382. userindex(self.window) # 显示主窗口 销毁本窗口
  383. class Look:
  384. def __init__(self, parent_window):
  385. parent_window.destroy() # 自动销毁上一个界面
  386. self.window = Tk() # 初始框的声明
  387. self.window.title('查看订单界面')
  388. self.window.geometry("600x600+300+0") # 初始窗口在屏幕中的位置
  389. self.frame_center = tk.Frame(width=600, height=400)
  390. self.frame_bottom = tk.Frame(width=650, height=70)
  391. self.columns = ( "电影名字", "放映厅", "放映时间", "价格","座位号")
  392. self.tree = ttk.Treeview(self.frame_center, show="headings", height=30, columns=self.columns)
  393. # 添加竖直滚动条
  394. self.vbar = ttk.Scrollbar(self.frame_center, orient=VERTICAL, command=self.tree.yview)
  395. # 定义树形结构与滚动条
  396. self.tree.configure(yscrollcommand=self.vbar.set)
  397. self.vbar.config(command=self.tree.yview())
  398. # 定义id1为修改id时的暂存变量,这个是为了更新信息而设计的
  399. self.id1 = 0
  400. # 表示列,不显示
  401. self.tree.column("电影名字", width=120, anchor='center')
  402. self.tree.column("放映厅", width=120, anchor='center')
  403. self.tree.column("放映时间", width=120, anchor='center')
  404. self.tree.column("价格", width=120, anchor='center')
  405. self.tree.column("座位号", width=120, anchor='center')
  406. # grid方法将tree和vbar进行布局
  407. self.tree.grid(row=0, column=0, sticky=NSEW)
  408. self.vbar.grid(row=0, column=1, sticky=NS)
  409. #下方
  410. self.var_movie_mane = StringVar() # 声明游客账号
  411. self.var_hall_id = StringVar() # 声明身份证号
  412. self.var_schedule_time = StringVar() # 声明联系电话
  413. self.var_schedule_price = StringVar() # 声明订票数量
  414. self.var_set_id=StringVar()
  415. # 定义下方区域,查询功能块
  416. self.chaxun = StringVar()
  417. self.right_bottom_gender_entry = Entry(self.frame_bottom, textvariable=self.chaxun, font=('Verdana', 15))
  418. self.right_bottom_button = ttk.Button(self.frame_bottom, text='查询订单', width=20, command=self.put_data)
  419. self.right_bottom_button.grid(row=0, column=0, padx=20, pady=20) # 位置设置
  420. self.right_bottom_gender_entry.grid(row=0, column=1)
  421. # 整体区域定位,利用了Frame和grid进行布局
  422. self.frame_center.grid(row=0, column=0, columnspan=2, padx=4, pady=5)
  423. self.frame_bottom.grid(row=1, column=0, columnspan=2)
  424. # 设置固定组件,(0)就是将组件进行了固定
  425. self.frame_center.grid_propagate(0)
  426. self.frame_bottom.grid_propagate(0)
  427. # 开始显示主菜单
  428. self.frame_center.tkraise() # 开始显示主菜单
  429. self.frame_bottom.tkraise() # 开始显示主菜单
  430. self.window.protocol("WM_DELETE_WINDOW", self.back) # 捕捉右上角关闭点击,执行back方法
  431. self.window.mainloop() # 进入消息循环
  432. def put_data(self):
  433. self.delButton()
  434. print(self.chaxun.get()) # 输入框内的内容
  435. # 打开数据库连接,准备查找指定的信息
  436. # 再次进行初始化,进行首行数据的插入
  437. con = pymysql.connect(host='localhost', port=3306, user='root', passwd='112233', db='dyy', charset='utf8')
  438. cursor = con.cursor() # 使用cursor()方法获取操作游标
  439. # sql = "use EMIS exec proc_cha '%s'" % (self.chaxun.get())
  440. sql = "SELECT * FROM table_userbuy WHERE user_id = '%s' " % (self.chaxun.get())
  441. try:
  442. # 执行SQL语句2
  443. cursor.execute(sql)
  444. # 获取所有记录列表
  445. results = cursor.fetchall()
  446. self.set_id = []
  447. for r in results:
  448. self.schedule_id=r[1]
  449. self.set_id.append(r[3])
  450. print(self.schedule_id)
  451. print(self.set_id)
  452. except:
  453. print("Error: unable to fetch data")
  454. messagebox.showinfo('警告!', '数据库连接失败!')
  455. con.close() # 关闭数据库连接
  456. con = pymysql.connect(host='localhost', port=3306, user='root', passwd='112233', db='dyy', charset='utf8')
  457. cursor = con.cursor() # 使用cursor()方法获取操作游标
  458. # sql = "use EMIS exec proc_cha '%s'" % (self.chaxun.get())
  459. sql1 = "SELECT * FROM table_schedule WHERE schedule_id = '%s' " % (self.schedule_id)
  460. try:
  461. # 执行SQL语句2
  462. cursor.execute(sql1)
  463. # 获取所有记录列表
  464. results = cursor.fetchall()
  465. self.schedule_movie = [] # 游客账号
  466. self.hall_id = [] # 身份证号
  467. self.schedule_time = [] # 联系电话
  468. self.schedule_price = [] # 订票数量
  469. for row in results:
  470. self.schedule_time.append(row[2])
  471. self.schedule_price.append(row[1])
  472. self.hall_id.append(row[4])
  473. self.schedule_movie.append(row[5])
  474. except:
  475. print("Error: unable to fetch data")
  476. messagebox.showinfo('警告!', '数据库连接失败!')
  477. con.close() # 关闭数据库连接
  478. print("进行数据的插入")
  479. for i in range(min(len(self.schedule_movie), len(self.hall_id), len(self.schedule_time), len(self.schedule_price),len(self.set_id))): # 写入数据
  480. self.tree.insert('', i, values=(
  481. self.schedule_movie[i], self.hall_id[i], self.schedule_time[i], self.schedule_price[i],self.set_id[i]))
  482. for col in self.columns: # 绑定函数,使表头可排序
  483. self.tree.heading(col, text=col, command=lambda _col=col: self.tree_sort_column(self.tree, _col, False))
  484. def delButton(self):
  485. x = self.tree.get_children()
  486. for item in x:
  487. self.tree.delete(item)
  488. def tree_sort_column(self, tv, col, reverse): # Treeview、列名、排列方式
  489. l = [(tv.set(k, col), k) for k in tv.get_children('')]
  490. l.sort(reverse=reverse) # 排序方式
  491. for index, (val, k) in enumerate(l): # 根据排序后索引移动
  492. tv.move(k, '', index)
  493. tv.heading(col, command=lambda: self.tree_sort_column(tv, col, not reverse)) # 重写标题,使之成为再点倒序的标题
  494. def back(self):
  495. userindex(self.window)
  496. class UserSign:
  497. def __init__(self, parent_window):
  498. parent_window.destroy() # 销毁主界面
  499. self.window = tk.Tk() # 初始框的声明
  500. self.window.title('用户注册页面')
  501. self.window.geometry('600x600') # 这里的乘是小x
  502. self.window.geometry('+330+0')
  503. self.admin_userid = [] # 账号
  504. self.admin_pass = [] # 密码
  505. self.admin_name = [] # 姓名
  506. self.admin_birth = [] # sr
  507. self.admin_phone = [] # 电话
  508. # 打开数据库连接
  509. con = pymysql.connect(host='localhost', port=3306, user='root', passwd='112233', db='dyy', charset='utf8')
  510. cursor = con.cursor() # 使用cursor()方法获取操作游标
  511. sql = "SELECT * FROM 用户信息" # SQL 查询语句
  512. try:
  513. # 执行SQL语句
  514. cursor.execute(sql)
  515. # 获取所有记录列表
  516. results = cursor.fetchall()
  517. for row in results:
  518. self.admin_userid.append(row[0])
  519. self.admin_pass.append(row[4])
  520. self.admin_name.append(row[1])
  521. self.admin_birth.append(row[3])
  522. self.admin_phone.append(row[2])
  523. except:
  524. print("Error: unable to fetch data")
  525. messagebox.showinfo('警告!', '数据库连接失败!')
  526. con.close() # 关闭数据库连接
  527. self.var_userid = StringVar() # 声明管理员账号
  528. self.var_pass = StringVar() # 声明管理员密码
  529. self.var_name = StringVar() # 声明管理员姓名
  530. self.var_birth = StringVar() # 声明管理员sr
  531. self.var_phone = StringVar() # 声明管理员电话
  532. label = tk.Label(self.window, text='用户注册', bg='green', font=('Verdana', 30), width=40, height=3)
  533. label.pack()
  534. Label(self.window, text='账号:', font=tkFont.Font(size=15)).pack(pady=10, anchor='w')
  535. self.var_userid = tk.Entry(self.window, width=40, font=tkFont.Font(size=20), bg='Ivory')
  536. self.var_userid.pack(anchor='nw')
  537. Label(self.window, text='密码:', font=tkFont.Font(size=15)).pack(pady=10, anchor='w')
  538. self.var_pass = tk.Entry(self.window, width=40, font=tkFont.Font(size=20), bg='Ivory', show='*')
  539. self.var_pass.pack(anchor='nw')
  540. Label(self.window, text='姓名:', font=tkFont.Font(size=15)).pack(pady=10, anchor='w')
  541. self.var_name = tk.Entry(self.window, width=40, font=tkFont.Font(size=20), bg='Ivory')
  542. self.var_name.pack(anchor='nw')
  543. Label(self.window, text='生日:', font=tkFont.Font(size=15)).pack(pady=10, anchor='w')
  544. self.var_birth = tk.Entry(self.window, width=40, font=tkFont.Font(size=20), bg='Ivory')
  545. self.var_birth.pack(anchor='nw')
  546. Label(self.window, text='联系电话:', font=tkFont.Font(size=15)).pack(pady=10, anchor='w')
  547. self.var_phone = tk.Entry(self.window, width=40, font=tkFont.Font(size=20), bg='Ivory')
  548. self.var_phone.pack(anchor='nw')
  549. Button(self.window, text="注册", width=20, font=tkFont.Font(size=15), command=self.new_row).pack(pady=20)
  550. Button(self.window, text="返回首页", width=20, font=tkFont.Font(size=15), command=self.back).pack(pady=20)
  551. self.window.protocol("WM_DELETE_WINDOW", self.back) # 捕捉右上角关闭点击
  552. self.window.mainloop() # 进入消息循环
  553. def new_row(self):
  554. # 从界面获取的数据
  555. print(self.var_userid.get())
  556. print(self.admin_userid)
  557. if str(self.var_userid.get()) in self.admin_userid:
  558. messagebox.showinfo('警告!', '该用户已存在!')
  559. elif (len(str(self.var_phone.get())) > 15) or (len(str(self.var_phone.get())) < 7):
  560. messagebox.showinfo('警告!', '请输入正确的电话号码!')
  561. else:
  562. if self.var_userid.get() != '' and self.var_pass.get() != '' and self.var_name.get() != '' and self.var_birth.get() != '' and self.var_phone.get() != '':
  563. # 打开数据库连接
  564. con = pymysql.connect(host='localhost', port=3306, user='root', passwd='112233', db='dyy',
  565. charset='utf8')
  566. cursor = con.cursor() # 使用cursor()方法获取操作游标
  567. sql = "INSERT INTO 用户信息(用户账号,用户密码,用户名,生日,手机号码) \
  568. VALUES ('%s', '%s', '%s', '%s', '%s')" % \
  569. (self.var_userid.get(), self.var_pass.get(), self.var_name.get(), self.var_birth.get(),
  570. self.var_phone.get()) # SQL 插入语句
  571. try:
  572. cursor.execute(sql) # 执行sql语句
  573. con.commit() # 提交到数据库执行
  574. except:
  575. con.rollback() # 发生错误时回滚
  576. messagebox.showinfo('警告!', '数据库连接失败!')
  577. con.close() # 关闭数据库连接
  578. self.admin_userid.append(self.var_userid.get())
  579. self.admin_pass.append(self.var_pass.get())
  580. self.admin_name.append(self.var_name.get())
  581. self.admin_birth.append(self.var_birth.get())
  582. self.admin_phone.append(self.var_phone.get())
  583. messagebox.showinfo('提示!', '注册成功!')
  584. else:
  585. messagebox.showinfo('警告!', '请填写正确的信息')
  586. def back(self):
  587. beginpage(self.window) # 显示主窗口 销毁本窗口
  588. class lookmovie:
  589. def __init__(self, parent_window):
  590. parent_window.destroy() # 销毁主界面
  591. self.window = Tk() # 初始框的声明
  592. self.window.title('管理员操作界面')
  593. self.frame_left_top = tk.Frame(width=300, height=200)
  594. self.frame_right_top = tk.Frame(width=200, height=200)
  595. self.frame_center = tk.Frame(width=500, height=400)
  596. self.frame_bottom = tk.Frame(width=650, height=50)
  597. # 定义下方中心列表区域
  598. self.columns = ("电影编号", "电影名字", "主演", "导演","简介")
  599. self.tree = ttk.Treeview(self.frame_center, show="headings", height=18, columns=self.columns)
  600. self.vbar = ttk.Scrollbar(self.frame_center, orient=VERTICAL, command=self.tree.yview)
  601. # 定义树形结构与滚动条
  602. self.tree.configure(yscrollcommand=self.vbar.set)
  603. # 表格的标题
  604. self.tree.column("电影编号", width=100, anchor='center') # 表示列,不显示
  605. self.tree.column("电影名字", width=100, anchor='center')
  606. self.tree.column("主演", width=100, anchor='center')
  607. self.tree.column("导演", width=100, anchor='center')
  608. self.tree.column("简介", width=100, anchor='center')
  609. # 调用方法获取表格内容插入
  610. self.tree.grid(row=0, column=0, sticky=NSEW)
  611. self.vbar.grid(row=0, column=1, sticky=NS)
  612. self.id = []
  613. self.name = []
  614. self.zhuyan = []
  615. self.daoyan = []
  616. self.jianjie=[]
  617. # 打开数据库连接
  618. con = pymysql.connect(host='localhost', port=3306, user='root', passwd='112233', db='dyy',
  619. charset='utf8')
  620. cursor = con.cursor() # 使用cursor()方法获取操作游标
  621. sql = "SELECT * FROM table_movie" # SQL 查询语句
  622. try:
  623. # 执行SQL语句
  624. cursor.execute(sql)
  625. # 获取所有记录列表
  626. results = cursor.fetchall()
  627. for row in results:
  628. self.id.append(row[0])
  629. self.name.append(row[1])
  630. self.zhuyan.append(row[2])
  631. self.daoyan.append(row[3])
  632. self.jianjie.append(row[4])
  633. except:
  634. print("Error: unable to fetch data")
  635. messagebox.showinfo('警告!', '数据库连接失败!')
  636. con.close() # 关闭数据库连接
  637. print("test***********************")
  638. for i in range(min(len(self.id), len(self.name), len(self.zhuyan), len(self.daoyan),len(self.jianjie))): # 写入数据
  639. self.tree.insert('', i, values=(self.id[i], self.name[i], self.zhuyan[i], self.daoyan[i],self.jianjie[i]))
  640. for col in self.columns: # 绑定函数,使表头可排序
  641. self.tree.heading(col, text=col,
  642. command=lambda _col=col: self.tree_sort_column(self.tree, _col, False))
  643. # 定义顶部区域
  644. # 定义左上方区域
  645. self.top_title = Label(self.frame_left_top, text="电影信息:", font=('Verdana', 20))
  646. self.top_title.grid(row=0, column=0, columnspan=2, sticky=NSEW, padx=50, pady=0)
  647. self.left_top_frame = tk.Frame(self.frame_left_top)
  648. self.var_id = StringVar() # 声明dy号
  649. self.var_name = StringVar() # 声明dy名
  650. self.var_zhuyan = StringVar() # 声明zy
  651. self.var_daoyan = StringVar() # 声明dyan
  652. self.var_jianjie=StringVar()
  653. # dy号
  654. self.right_top_id_label = Label(self.frame_left_top, text="电影编号:", font=('Verdana', 15))
  655. self.right_top_id_entry = Entry(self.frame_left_top, textvariable=self.var_id, font=('Verdana', 15))
  656. self.right_top_id_label.grid(row=1, column=0) # 位置设置
  657. self.right_top_id_entry.grid(row=1, column=1)
  658. # 姓名
  659. self.right_top_name_label = Label(self.frame_left_top, text="电影名字:", font=('Verdana', 15))
  660. self.right_top_name_entry = Entry(self.frame_left_top, textvariable=self.var_name, font=('Verdana', 15))
  661. self.right_top_name_label.grid(row=2, column=0) # 位置设置
  662. self.right_top_name_entry.grid(row=2, column=1)
  663. # 性别
  664. self.right_top_gender_label = Label(self.frame_left_top, text="主演:", font=('Verdana', 15))
  665. self.right_top_gender_entry = Entry(self.frame_left_top, textvariable=self.var_zhuyan,
  666. font=('Verdana', 15))
  667. self.right_top_gender_label.grid(row=3, column=0) # 位置设置
  668. self.right_top_gender_entry.grid(row=3, column=1)
  669. # 年龄
  670. self.right_top_gender_label = Label(self.frame_left_top, text="导演:", font=('Verdana', 15))
  671. self.right_top_gender_entry = Entry(self.frame_left_top, textvariable=self.var_daoyan,
  672. font=('Verdana', 15))
  673. self.right_top_gender_label.grid(row=4, column=0) # 位置设置
  674. self.right_top_gender_entry.grid(row=4, column=1)
  675. # 年龄
  676. self.right_top_gender_label = Label(self.frame_left_top, text="简介:", font=('Verdana', 15))
  677. self.right_top_gender_entry = Entry(self.frame_left_top, textvariable=self.var_jianjie,
  678. font=('Verdana', 15))
  679. self.right_top_gender_label.grid(row=5, column=0) # 位置设置
  680. self.right_top_gender_entry.grid(row=5, column=1)
  681. # 定义右上方区域
  682. self.right_top_title = Label(self.frame_right_top, text="操作:", font=('Verdana', 20))
  683. self.tree.bind('<Button-1>', self.click) # 左键获取位置
  684. self.right_top_button1 = ttk.Button(self.frame_right_top, text='新建电影信息', width=20, command=self.new_row)
  685. self.right_top_button2 = ttk.Button(self.frame_right_top, text='更新选中电影信息', width=20,
  686. command=self.updata_row)
  687. self.right_top_button3 = ttk.Button(self.frame_right_top, text='删除选中电影信息', width=20,
  688. command=self.del_row)
  689. # 位置设置
  690. self.right_top_title.grid(row=1, column=0, pady=10)
  691. self.right_top_button1.grid(row=2, column=0, padx=20, pady=10)
  692. self.right_top_button2.grid(row=3, column=0, padx=20, pady=10)
  693. self.right_top_button3.grid(row=4, column=0, padx=20, pady=10)
  694. # 整体区域定位
  695. self.frame_left_top.grid(row=0, column=0, padx=2, pady=5)
  696. self.frame_right_top.grid(row=0, column=1, padx=30, pady=30)
  697. self.frame_center.grid(row=1, column=0, columnspan=2, padx=4, pady=5)
  698. self.frame_bottom.grid(row=2, column=0, columnspan=2)
  699. self.frame_left_top.grid_propagate(0)
  700. self.frame_right_top.grid_propagate(0)
  701. self.frame_center.grid_propagate(0)
  702. self.frame_bottom.grid_propagate(0)
  703. self.frame_left_top.tkraise() # 开始显示主菜单
  704. self.frame_right_top.tkraise() # 开始显示主菜单
  705. self.frame_center.tkraise() # 开始显示主菜单
  706. self.frame_bottom.tkraise() # 开始显示主菜单
  707. self.window.protocol("WM_DELETE_WINDOW", self.back) # 捕捉右上角关闭点击
  708. self.window.mainloop() # 进入消息循环
  709. def back(self):
  710. adminMessage(self.window) # 显示主窗口 销毁本窗口
  711. def click(self, event):
  712. self.col = self.tree.identify_column(event.x) # 列
  713. self.row = self.tree.identify_row(event.y) # 行
  714. print(self.col)
  715. print(self.row)
  716. self.row_info = self.tree.item(self.row, "values")
  717. self.var_id.set(self.row_info[0])
  718. self.var_name.set(self.row_info[1])
  719. self.var_zhuyan.set(self.row_info[2])
  720. self.var_daoyan.set(self.row_info[3])
  721. self.var_jianjie.set(self.row_info[4])
  722. self.right_top_id_entry = Entry(self.frame_left_top, state='disabled', textvariable=self.var_id,
  723. font=('Verdana', 15))
  724. print('')
  725. def tree_sort_column(self, tv, col, reverse): # Treeview、列名、排列方式
  726. l = [(tv.set(k, col), k) for k in tv.get_children('')]
  727. l.sort(reverse=reverse) # 排序方式
  728. # rearrange items in sorted positions
  729. for index, (val, k) in enumerate(l): # 根据排序后索引移动
  730. tv.move(k, '', index)
  731. tv.heading(col, command=lambda: self.tree_sort_column(tv, col, not reverse)) # 重写标题,使之成为再点倒序的标题
  732. def new_row(self):
  733. print('123')
  734. print(self.var_id.get())
  735. print(self.id)
  736. if str(self.var_id.get()) in self.id:
  737. messagebox.showinfo('警告!', '该电影已存在!')
  738. else:
  739. if self.var_id.get() != '' and self.var_name.get() != '' and self.var_zhuyan.get() != '' and self.var_daoyan.get() != ''and self.var_jianjie.get() !='':
  740. # 打开数据库连接
  741. con = pymysql.connect(host='localhost', port=3306, user='root', passwd='112233', db='dyy',
  742. charset='utf8')
  743. cursor = con.cursor() # 使用cursor()方法获取操作游标
  744. sql = "INSERT INTO table_movie(movie_id, movie_name, movie_zhuyan, movie_daoyan,movie_jianjie) \
  745. VALUES ('%s', '%s', '%s', '%s','%s')" % \
  746. (self.var_id.get(), self.var_name.get(), self.var_zhuyan.get(), self.var_daoyan.get(),self.var_jianjie.get()) # SQL 插入语句
  747. try:
  748. cursor.execute(sql) # 执行sql语句
  749. con.commit() # 提交到数据库执行
  750. except:
  751. con.rollback() # 发生错误时回滚
  752. messagebox.showinfo('警告!', '数据库连接失败!')
  753. con.close() # 关闭数据库连接
  754. self.id.append(self.var_id.get())
  755. self.name.append(self.var_name.get())
  756. self.zhuyan.append(self.var_zhuyan.get())
  757. self.daoyan.append(self.var_daoyan.get())
  758. self.jianjie.append(self.var_jianjie.get())
  759. self.tree.insert('', len(self.id) - 1, values=(
  760. self.id[len(self.id) - 1], self.name[len(self.id) - 1], self.zhuyan[len(self.id) - 1],
  761. self.daoyan[len(self.id) - 1],self.jianjie[len(self.id)-1]))
  762. self.tree.update()
  763. messagebox.showinfo('提示!', '插入成功!')
  764. else:
  765. messagebox.showinfo('警告!', '请填写订单数据')
  766. def updata_row(self):
  767. res = messagebox.askyesnocancel('警告!', '是否更新所填数据?')
  768. if res == True:
  769. if self.var_id.get() == self.row_info[0]: # 如果所填学号 与 所选学号一致
  770. # 打开数据库连接
  771. con = pymysql.connect(host='localhost', port=3306, user='root', passwd='112233', db='dyy',
  772. charset='utf8')
  773. cursor = con.cursor() # 使用cursor()方法获取操作游标
  774. sql = "UPDATE table_movie SET movie_name = '%s', movie_zhuyan = '%s', movie_daoyan = '%s',moive_jianjie ='%s' \
  775. WHERE movie_id = '%s'" % (
  776. self.var_name.get(), self.var_zhuyan.get(), self.var_daoyan.get(), self.var_jianjie.get(),self.var_id.get()) # SQL 插入语句
  777. try:
  778. cursor.execute(sql) # 执行sql语句
  779. con.commit() # 提交到数据库执行
  780. messagebox.showinfo('提示!', '更新成功!')
  781. except:
  782. con.rollback() # 发生错误时回滚
  783. con.close() # 关闭数据库连接
  784. id_index = self.id.index(self.row_info[0])
  785. self.name[id_index] = self.var_name.get()
  786. self.zhuyan[id_index] = self.var_zhuyan.get()
  787. self.daoyan[id_index] = self.var_daoyan.get()
  788. self.jianjie[id_index]=self.var_jianjie.get()
  789. self.tree.item(self.tree.selection()[0], values=(
  790. self.var_id.get(), self.var_name.get(), self.var_zhuyan.get(),
  791. self.var_daoyan.get(),self.var_jianjie.get())) # 修改对于行信息
  792. else:
  793. messagebox.showinfo('警告!', '不能修改订单号!')
  794. def del_row(self):
  795. res = messagebox.askyesnocancel('警告!', '是否删除所选数据?')
  796. if res == True:
  797. print(self.row_info[0]) # 鼠标选中的学号
  798. print(self.tree.selection()[0]) # 行号
  799. print(self.tree.get_children()) # 所有行
  800. # 打开数据库连接
  801. con = pymysql.connect(host='localhost', port=3306, user='root', passwd='112233', db='dyy',
  802. charset='utf8')
  803. cursor = con.cursor() # 使用cursor()方法获取操作游标
  804. sql = "DELETE FROM table_movie WHERE movie_id = '%s'" % (self.row_info[0]) # SQL 插入语句
  805. try:
  806. cursor.execute(sql) # 执行sql语句
  807. con.commit() # 提交到数据库执行
  808. messagebox.showinfo('提示!', '删除成功!')
  809. except:
  810. con.rollback() # 发生错误时回滚
  811. messagebox.showinfo('警告!', '删除失败,数据库连接失败!')
  812. con.close() # 关闭数据库连接
  813. id_index = self.id.index(self.row_info[0])
  814. print(id_index)
  815. del self.id[id_index]
  816. del self.name[id_index]
  817. del self.zhuyan[id_index]
  818. del self.daoyan[id_index]
  819. del self.jianjie[id_index]
  820. print(self.id)
  821. self.tree.delete(self.tree.selection()[0]) # 删除所选行
  822. print(self.tree.get_children())
  823. class adlook:
  824. def __init__(self, parent_window):
  825. parent_window.destroy() # 销毁主界面
  826. self.window = Tk() # 初始框的声明
  827. self.window.title('管理员操作界面')
  828. self.frame_left_top = tk.Frame(width=300, height=200)
  829. self.frame_right_top = tk.Frame(width=200, height=200)
  830. self.frame_center = tk.Frame(width=500, height=400)
  831. self.frame_bottom = tk.Frame(width=650, height=50)
  832. # 定义下方中心列表区域
  833. self.columns = ("订单号", "排片编号", "用户账号", "座位号")
  834. self.tree = ttk.Treeview(self.frame_center, show="headings", height=18, columns=self.columns)
  835. self.vbar = ttk.Scrollbar(self.frame_center, orient=VERTICAL, command=self.tree.yview)
  836. # 定义树形结构与滚动条
  837. self.tree.configure(yscrollcommand=self.vbar.set)
  838. # 表格的标题
  839. self.tree.column("订单号", width=150, anchor='center') # 表示列,不显示
  840. self.tree.column("排片编号", width=150, anchor='center')
  841. self.tree.column("用户账号", width=100, anchor='center')
  842. self.tree.column("座位号", width=100, anchor='center')
  843. # 调用方法获取表格内容插入
  844. self.tree.grid(row=0, column=0, sticky=NSEW)
  845. self.vbar.grid(row=0, column=1, sticky=NS)
  846. self.id = []
  847. self.name = []
  848. self.gender = []
  849. self.age = []
  850. # 打开数据库连接
  851. con = pymysql.connect(host='localhost', port=3306, user='root', passwd='112233', db='dyy',
  852. charset='utf8')
  853. cursor = con.cursor() # 使用cursor()方法获取操作游标
  854. sql = "SELECT * FROM table_userbuy" # SQL 查询语句
  855. try:
  856. # 执行SQL语句
  857. cursor.execute(sql)
  858. # 获取所有记录列表
  859. results = cursor.fetchall()
  860. for row in results:
  861. self.id.append(row[0])
  862. self.name.append(row[1])
  863. self.gender.append(row[2])
  864. self.age.append(row[3])
  865. # print(self.id)
  866. # print(self.name)
  867. # print(self.gender)
  868. # print(self.age)
  869. except:
  870. print("Error: unable to fetch data")
  871. messagebox.showinfo('警告!', '数据库连接失败!')
  872. con.close() # 关闭数据库连接
  873. print("test***********************")
  874. for i in range(min(len(self.id), len(self.name), len(self.gender), len(self.age))): # 写入数据
  875. self.tree.insert('', i, values=(self.id[i], self.name[i], self.gender[i], self.age[i]))
  876. for col in self.columns: # 绑定函数,使表头可排序
  877. self.tree.heading(col, text=col,
  878. command=lambda _col=col: self.tree_sort_column(self.tree, _col, False))
  879. # 定义顶部区域
  880. # 定义左上方区域
  881. self.top_title = Label(self.frame_left_top, text="订单信息:", font=('Verdana', 20))
  882. self.top_title.grid(row=0, column=0, columnspan=2, sticky=NSEW, padx=50, pady=10)
  883. self.left_top_frame = tk.Frame(self.frame_left_top)
  884. self.var_id = StringVar() # 声明学号
  885. self.var_name = StringVar() # 声明姓名
  886. self.var_gender = StringVar() # 声明性别
  887. self.var_age = StringVar() # 声明年龄
  888. # 学号
  889. self.right_top_id_label = Label(self.frame_left_top, text="订单号:", font=('Verdana', 15))
  890. self.right_top_id_entry = Entry(self.frame_left_top, textvariable=self.var_id, font=('Verdana', 15))
  891. self.right_top_id_label.grid(row=1, column=0) # 位置设置
  892. self.right_top_id_entry.grid(row=1, column=1)
  893. # 姓名
  894. self.right_top_name_label = Label(self.frame_left_top, text="排片编号:", font=('Verdana', 15))
  895. self.right_top_name_entry = Entry(self.frame_left_top, textvariable=self.var_name, font=('Verdana', 15))
  896. self.right_top_name_label.grid(row=2, column=0) # 位置设置
  897. self.right_top_name_entry.grid(row=2, column=1)
  898. # 性别
  899. self.right_top_gender_label = Label(self.frame_left_top, text="用户账号:", font=('Verdana', 15))
  900. self.right_top_gender_entry = Entry(self.frame_left_top, textvariable=self.var_gender,
  901. font=('Verdana', 15))
  902. self.right_top_gender_label.grid(row=3, column=0) # 位置设置
  903. self.right_top_gender_entry.grid(row=3, column=1)
  904. # 年龄
  905. self.right_top_gender_label = Label(self.frame_left_top, text="座位号:", font=('Verdana', 15))
  906. self.right_top_gender_entry = Entry(self.frame_left_top, textvariable=self.var_age,
  907. font=('Verdana', 15))
  908. self.right_top_gender_label.grid(row=4, column=0) # 位置设置
  909. self.right_top_gender_entry.grid(row=4, column=1)
  910. # 定义右上方区域
  911. self.right_top_title = Label(self.frame_right_top, text="操作:", font=('Verdana', 20))
  912. self.tree.bind('<Button-1>', self.click) # 左键获取位置
  913. self.right_top_button1 = ttk.Button(self.frame_right_top, text='新建电影信息', width=20, command=self.new_row)
  914. self.right_top_button2 = ttk.Button(self.frame_right_top, text='更新选中电影信息', width=20,
  915. command=self.updata_row)
  916. self.right_top_button3 = ttk.Button(self.frame_right_top, text='删除选中电影信息', width=20,
  917. command=self.del_row)
  918. # 位置设置
  919. self.right_top_title.grid(row=1, column=0, pady=10)
  920. self.right_top_button1.grid(row=2, column=0, padx=20, pady=10)
  921. self.right_top_button2.grid(row=3, column=0, padx=20, pady=10)
  922. self.right_top_button3.grid(row=4, column=0, padx=20, pady=10)
  923. # 整体区域定位
  924. self.frame_left_top.grid(row=0, column=0, padx=2, pady=5)
  925. self.frame_right_top.grid(row=0, column=1, padx=30, pady=30)
  926. self.frame_center.grid(row=1, column=0, columnspan=2, padx=4, pady=5)
  927. self.frame_bottom.grid(row=2, column=0, columnspan=2)
  928. self.frame_left_top.grid_propagate(0)
  929. self.frame_right_top.grid_propagate(0)
  930. self.frame_center.grid_propagate(0)
  931. self.frame_bottom.grid_propagate(0)
  932. self.frame_left_top.tkraise() # 开始显示主菜单
  933. self.frame_right_top.tkraise() # 开始显示主菜单
  934. self.frame_center.tkraise() # 开始显示主菜单
  935. self.frame_bottom.tkraise() # 开始显示主菜单
  936. self.window.protocol("WM_DELETE_WINDOW", self.back) # 捕捉右上角关闭点击
  937. self.window.mainloop() # 进入消息循环
  938. def back(self):
  939. adminMessage(self.window) # 显示主窗口 销毁本窗口
  940. def click(self, event):
  941. self.col = self.tree.identify_column(event.x) # 列
  942. self.row = self.tree.identify_row(event.y) # 行
  943. print(self.col)
  944. print(self.row)
  945. self.row_info = self.tree.item(self.row, "values")
  946. self.var_id.set(self.row_info[0])
  947. self.var_name.set(self.row_info[1])
  948. self.var_gender.set(self.row_info[2])
  949. self.var_age.set(self.row_info[3])
  950. self.right_top_id_entry = Entry(self.frame_left_top, state='disabled', textvariable=self.var_id,
  951. font=('Verdana', 15))
  952. print('')
  953. def tree_sort_column(self, tv, col, reverse): # Treeview、列名、排列方式
  954. l = [(tv.set(k, col), k) for k in tv.get_children('')]
  955. l.sort(reverse=reverse) # 排序方式
  956. # rearrange items in sorted positions
  957. for index, (val, k) in enumerate(l): # 根据排序后索引移动
  958. tv.move(k, '', index)
  959. tv.heading(col, command=lambda: self.tree_sort_column(tv, col, not reverse)) # 重写标题,使之成为再点倒序的标题
  960. def new_row(self):
  961. print('123')
  962. print(self.var_id.get())
  963. print(self.id)
  964. if str(self.var_id.get()) in self.id:
  965. messagebox.showinfo('警告!', '该订单已存在!')
  966. else:
  967. if self.var_id.get() != '' and self.var_name.get() != '' and self.var_gender.get() != '' and self.var_age.get() != '':
  968. # 打开数据库连接
  969. con = pymysql.connect(host='localhost', port=3306, user='root', passwd='112233', db='dyy',
  970. charset='utf8')
  971. cursor = con.cursor() # 使用cursor()方法获取操作游标
  972. sql = "INSERT INTO table_userbuy(userbuy_id, schedule_id, user_id, set_id) \
  973. VALUES ('%s', '%s', '%s', '%s')" % \
  974. (self.var_id.get(), self.var_name.get(), self.var_gender.get(), self.var_age.get()) # SQL 插入语句
  975. try:
  976. cursor.execute(sql) # 执行sql语句
  977. con.commit() # 提交到数据库执行
  978. except:
  979. con.rollback() # 发生错误时回滚
  980. messagebox.showinfo('警告!', '数据库连接失败!')
  981. con.close() # 关闭数据库连接
  982. self.id.append(self.var_id.get())
  983. self.name.append(self.var_name.get())
  984. self.gender.append(self.var_gender.get())
  985. self.age.append(self.var_age.get())
  986. self.tree.insert('', len(self.id) - 1, values=(
  987. self.id[len(self.id) - 1], self.name[len(self.id) - 1], self.gender[len(self.id) - 1],
  988. self.age[len(self.id) - 1]))
  989. self.tree.update()
  990. messagebox.showinfo('提示!', '插入成功!')
  991. else:
  992. messagebox.showinfo('警告!', '请填写订单数据')
  993. def updata_row(self):
  994. res = messagebox.askyesnocancel('警告!', '是否更新所填数据?')
  995. if res == True:
  996. if self.var_id.get() == self.row_info[0]: # 如果所填学号 与 所选学号一致
  997. # 打开数据库连接
  998. con = pymysql.connect(host='localhost', port=3306, user='root', passwd='112233', db='dyy',
  999. charset='utf8')
  1000. cursor = con.cursor() # 使用cursor()方法获取操作游标
  1001. sql = "UPDATE table_userbuy SET schedule_id = '%s', user_id = '%s', set_id = '%s' \
  1002. WHERE userbuy_id = '%s'" % (
  1003. self.var_name.get(), self.var_gender.get(), self.var_age.get(), self.var_id.get()) # SQL 插入语句
  1004. try:
  1005. cursor.execute(sql) # 执行sql语句
  1006. con.commit() # 提交到数据库执行
  1007. messagebox.showinfo('提示!', '更新成功!')
  1008. except:
  1009. con.rollback() # 发生错误时回滚
  1010. messagebox.showinfo('警告!', '更新失败,数据库连接失败!')
  1011. con.close() # 关闭数据库连接
  1012. id_index = self.id.index(self.row_info[0])
  1013. self.name[id_index] = self.var_name.get()
  1014. self.gender[id_index] = self.var_gender.get()
  1015. self.age[id_index] = self.var_age.get()
  1016. self.tree.item(self.tree.selection()[0], values=(
  1017. self.var_id.get(), self.var_name.get(), self.var_gender.get(),
  1018. self.var_age.get())) # 修改对于行信息
  1019. else:
  1020. messagebox.showinfo('警告!', '不能修改订单号!')
  1021. def del_row(self):
  1022. res = messagebox.askyesnocancel('警告!', '是否删除所选数据?')
  1023. if res == True:
  1024. print(self.row_info[0]) # 鼠标选中的学号
  1025. print(self.tree.selection()[0]) # 行号
  1026. print(self.tree.get_children()) # 所有行
  1027. # 打开数据库连接
  1028. con = pymysql.connect(host='localhost', port=3306, user='root', passwd='112233', db='dyy',
  1029. charset='utf8')
  1030. cursor = con.cursor() # 使用cursor()方法获取操作游标
  1031. sql = "DELETE FROM table_userbuy WHERE userbuy_id = '%s'" % (self.row_info[0]) # SQL 插入语句
  1032. try:
  1033. cursor.execute(sql) # 执行sql语句
  1034. con.commit() # 提交到数据库执行
  1035. messagebox.showinfo('提示!', '删除成功!')
  1036. except:
  1037. con.rollback() # 发生错误时回滚
  1038. messagebox.showinfo('警告!', '删除失败,数据库连接失败!')
  1039. con.close() # 关闭数据库连接
  1040. id_index = self.id.index(self.row_info[0])
  1041. print(id_index)
  1042. del self.id[id_index]
  1043. del self.name[id_index]
  1044. del self.gender[id_index]
  1045. del self.age[id_index]
  1046. print(self.id)
  1047. self.tree.delete(self.tree.selection()[0]) # 删除所选行
  1048. print(self.tree.get_children())
  1049. class adpai:
  1050. def __init__(self, parent_window):
  1051. parent_window.destroy() # 销毁主界面
  1052. self.window = Tk() # 初始框的声明
  1053. self.window.title('排片操作界面')
  1054. self.frame_left_top = tk.Frame(width=300, height=200)
  1055. self.frame_right_top = tk.Frame(width=200, height=200)
  1056. self.frame_center = tk.Frame(width=500, height=400)
  1057. self.frame_bottom = tk.Frame(width=650, height=50)
  1058. # 定义下方中心列表区域
  1059. self.columns = ("排片编号", "电影名字", "价格", "时间","放映厅")
  1060. self.tree = ttk.Treeview(self.frame_center, show="headings", height=18, columns=self.columns)
  1061. self.vbar = ttk.Scrollbar(self.frame_center, orient=VERTICAL, command=self.tree.yview)
  1062. # 定义树形结构与滚动条
  1063. self.tree.configure(yscrollcommand=self.vbar.set)
  1064. # 表格的标题
  1065. self.tree.column("排片编号", width=100, anchor='center') # 表示列,不显示
  1066. self.tree.column("电影名字", width=100, anchor='center')
  1067. self.tree.column("价格", width=100, anchor='center')
  1068. self.tree.column("时间", width=100, anchor='center')
  1069. self.tree.column("放映厅", width=100, anchor='center')
  1070. # 调用方法获取表格内容插入
  1071. self.tree.grid(row=0, column=0, sticky=NSEW)
  1072. self.vbar.grid(row=0, column=1, sticky=NS)
  1073. self.id = []
  1074. self.name = []
  1075. self.zhuyan = []
  1076. self.daoyan = []
  1077. self.jianjie=[]
  1078. # 打开数据库连接
  1079. con = pymysql.connect(host='localhost', port=3306, user='root', passwd='112233', db='dyy',
  1080. charset='utf8')
  1081. cursor = con.cursor() # 使用cursor()方法获取操作游标
  1082. sql = "SELECT * FROM table_schedule" # SQL 查询语句
  1083. try:
  1084. # 执行SQL语句
  1085. cursor.execute(sql)
  1086. # 获取所有记录列表
  1087. results = cursor.fetchall()
  1088. for row in results:
  1089. self.id.append(row[0])
  1090. self.name.append(row[5])
  1091. self.zhuyan.append(row[1])
  1092. self.daoyan.append(row[2])
  1093. self.jianjie.append(row[4])
  1094. except:
  1095. print("Error: unable to fetch data")
  1096. messagebox.showinfo('警告!', '数据库连接失败!')
  1097. con.close() # 关闭数据库连接
  1098. print("test***********************")
  1099. for i in range(min(len(self.id), len(self.name), len(self.zhuyan), len(self.daoyan),len(self.jianjie))): # 写入数据
  1100. self.tree.insert('', i, values=(self.id[i], self.name[i], self.zhuyan[i], self.daoyan[i],self.jianjie[i]))
  1101. for col in self.columns: # 绑定函数,使表头可排序
  1102. self.tree.heading(col, text=col,
  1103. command=lambda _col=col: self.tree_sort_column(self.tree, _col, False))
  1104. # 定义顶部区域
  1105. # 定义左上方区域
  1106. self.top_title = Label(self.frame_left_top, text="排片信息:", font=('Verdana', 20))
  1107. self.top_title.grid(row=0, column=0, columnspan=2, sticky=NSEW, padx=50, pady=0)
  1108. self.left_top_frame = tk.Frame(self.frame_left_top)
  1109. self.var_id = StringVar() # 声明dy号
  1110. self.var_name = StringVar() # 声明dy名
  1111. self.var_zhuyan = StringVar() # 声明zy
  1112. self.var_daoyan = StringVar() # 声明dyan
  1113. self.var_jianjie=StringVar()
  1114. # dy号
  1115. self.right_top_id_label = Label(self.frame_left_top, text="排片编号:", font=('Verdana', 15))
  1116. self.right_top_id_entry = Entry(self.frame_left_top, textvariable=self.var_id, font=('Verdana', 15))
  1117. self.right_top_id_label.grid(row=1, column=0) # 位置设置
  1118. self.right_top_id_entry.grid(row=1, column=1)
  1119. # 姓名
  1120. self.right_top_name_label = Label(self.frame_left_top, text="电影名字:", font=('Verdana', 15))
  1121. self.right_top_name_entry = Entry(self.frame_left_top, textvariable=self.var_name, font=('Verdana', 15))
  1122. self.right_top_name_label.grid(row=2, column=0) # 位置设置
  1123. self.right_top_name_entry.grid(row=2, column=1)
  1124. # 性别
  1125. self.right_top_gender_label = Label(self.frame_left_top, text="价格:", font=('Verdana', 15))
  1126. self.right_top_gender_entry = Entry(self.frame_left_top, textvariable=self.var_zhuyan,
  1127. font=('Verdana', 15))
  1128. self.right_top_gender_label.grid(row=3, column=0) # 位置设置
  1129. self.right_top_gender_entry.grid(row=3, column=1)
  1130. # 年龄
  1131. self.right_top_gender_label = Label(self.frame_left_top, text="时间:", font=('Verdana', 15))
  1132. self.right_top_gender_entry = Entry(self.frame_left_top, textvariable=self.var_daoyan,
  1133. font=('Verdana', 15))
  1134. self.right_top_gender_label.grid(row=4, column=0) # 位置设置
  1135. self.right_top_gender_entry.grid(row=4, column=1)
  1136. # 年龄
  1137. self.right_top_gender_label = Label(self.frame_left_top, text="放映厅:", font=('Verdana', 15))
  1138. self.right_top_gender_entry = Entry(self.frame_left_top, textvariable=self.var_jianjie,
  1139. font=('Verdana', 15))
  1140. self.right_top_gender_label.grid(row=5, column=0) # 位置设置
  1141. self.right_top_gender_entry.grid(row=5, column=1)
  1142. # 定义右上方区域
  1143. self.right_top_title = Label(self.frame_right_top, text="操作:", font=('Verdana', 20))
  1144. self.tree.bind('<Button-1>', self.click) # 左键获取位置
  1145. self.right_top_button1 = ttk.Button(self.frame_right_top, text='新建排片信息', width=20, command=self.new_row)
  1146. self.right_top_button2 = ttk.Button(self.frame_right_top, text='更新选中排片信息', width=20,
  1147. command=self.updata_row)
  1148. self.right_top_button3 = ttk.Button(self.frame_right_top, text='删除选中排片信息', width=20,
  1149. command=self.del_row)
  1150. # 位置设置
  1151. self.right_top_title.grid(row=1, column=0, pady=10)
  1152. self.right_top_button1.grid(row=2, column=0, padx=20, pady=10)
  1153. self.right_top_button2.grid(row=3, column=0, padx=20, pady=10)
  1154. self.right_top_button3.grid(row=4, column=0, padx=20, pady=10)
  1155. # 整体区域定位
  1156. self.frame_left_top.grid(row=0, column=0, padx=2, pady=5)
  1157. self.frame_right_top.grid(row=0, column=1, padx=30, pady=30)
  1158. self.frame_center.grid(row=1, column=0, columnspan=2, padx=4, pady=5)
  1159. self.frame_bottom.grid(row=2, column=0, columnspan=2)
  1160. self.frame_left_top.grid_propagate(0)
  1161. self.frame_right_top.grid_propagate(0)
  1162. self.frame_center.grid_propagate(0)
  1163. self.frame_bottom.grid_propagate(0)
  1164. self.frame_left_top.tkraise() # 开始显示主菜单
  1165. self.frame_right_top.tkraise() # 开始显示主菜单
  1166. self.frame_center.tkraise() # 开始显示主菜单
  1167. self.frame_bottom.tkraise() # 开始显示主菜单
  1168. self.window.protocol("WM_DELETE_WINDOW", self.back) # 捕捉右上角关闭点击
  1169. self.window.mainloop() # 进入消息循环
  1170. def back(self):
  1171. adminMessage(self.window) # 显示主窗口 销毁本窗口
  1172. def click(self, event):
  1173. self.col = self.tree.identify_column(event.x) # 列
  1174. self.row = self.tree.identify_row(event.y) # 行
  1175. print(self.col)
  1176. print(self.row)
  1177. self.row_info = self.tree.item(self.row, "values")
  1178. self.var_id.set(self.row_info[0])
  1179. self.var_name.set(self.row_info[1])
  1180. self.var_zhuyan.set(self.row_info[2])
  1181. self.var_daoyan.set(self.row_info[3])
  1182. self.var_jianjie.set(self.row_info[4])
  1183. self.right_top_id_entry = Entry(self.frame_left_top, state='disabled', textvariable=self.var_id,
  1184. font=('Verdana', 15))
  1185. print('')
  1186. def tree_sort_column(self, tv, col, reverse): # Treeview、列名、排列方式
  1187. l = [(tv.set(k, col), k) for k in tv.get_children('')]
  1188. l.sort(reverse=reverse) # 排序方式
  1189. # rearrange items in sorted positions
  1190. for index, (val, k) in enumerate(l): # 根据排序后索引移动
  1191. tv.move(k, '', index)
  1192. tv.heading(col, command=lambda: self.tree_sort_column(tv, col, not reverse)) # 重写标题,使之成为再点倒序的标题
  1193. def new_row(self):
  1194. print('123')
  1195. print(self.var_id.get())
  1196. print(self.id)
  1197. if str(self.var_id.get()) in self.id:
  1198. messagebox.showinfo('警告!', '该电影已存在!')
  1199. else:
  1200. if self.var_id.get() != '' and self.var_name.get() != '' and self.var_zhuyan.get() != '' and self.var_daoyan.get() != ''and self.var_jianjie.get() !='':
  1201. # 打开数据库连接
  1202. con = pymysql.connect(host='localhost', port=3306, user='root', passwd='112233', db='dyy',
  1203. charset='utf8')
  1204. cursor = con.cursor() # 使用cursor()方法获取操作游标
  1205. sql = "SELECT * FROM table_movie WHERE movie_name = '%s'" % (self.var_name.get()) # SQL 查询语句
  1206. try:
  1207. # 执行SQL语句
  1208. cursor.execute(sql)
  1209. # 获取所有记录列表
  1210. results = cursor.fetchall()
  1211. for row in results:
  1212. self.movie_id=row[0]
  1213. print(self.movie_id)
  1214. except:
  1215. print("Error: unable to fetch data")
  1216. messagebox.showinfo('警告!', '数据库连接失败!')
  1217. con.close() # 关闭数据库连接
  1218. con = pymysql.connect(host='localhost', port=3306, user='root', passwd='112233', db='dyy',
  1219. charset='utf8')
  1220. cursor = con.cursor() # 使用cursor()方法获取操作游标
  1221. sql1 = "INSERT INTO table_schedule(schedule_id, schedule_price,schedule_time,movie_id,hall_id,schedule_movie) \
  1222. VALUES ('%s', '%s', '%s', '%s','%s','%s')" % \
  1223. (self.var_id.get(), self.var_daoyan.get(), self.var_zhuyan.get(),self.movie_id,self.var_jianjie.get(),self.var_name.get()) # SQL 插入语句
  1224. try:
  1225. cursor.execute(sql1) # 执行sql语句
  1226. con.commit() # 提交到数据库执行
  1227. except:
  1228. con.rollback() # 发生错误时回滚
  1229. messagebox.showinfo('警告!', '数据库连接失败!')
  1230. con.close() # 关闭数据库连接
  1231. self.id.append(self.var_id.get())
  1232. self.name.append(self.var_name.get())
  1233. self.zhuyan.append(self.var_zhuyan.get())
  1234. self.daoyan.append(self.var_daoyan.get())
  1235. self.jianjie.append(self.var_jianjie.get())
  1236. self.tree.insert('', len(self.id) - 1, values=(
  1237. self.id[len(self.id) - 1], self.name[len(self.id) - 1], self.zhuyan[len(self.id) - 1],
  1238. self.daoyan[len(self.id) - 1],self.jianjie[len(self.id)-1]))
  1239. self.tree.update()
  1240. messagebox.showinfo('提示!', '插入成功!')
  1241. else:
  1242. messagebox.showinfo('警告!', '请填写排片数据')
  1243. def updata_row(self):
  1244. res = messagebox.askyesnocancel('警告!', '是否更新所填数据?')
  1245. if res == True:
  1246. if self.var_id.get() == self.row_info[0]: # 如果所填学号 与 所选学号一致
  1247. # 打开数据库连接
  1248. con = pymysql.connect(host='localhost', port=3306, user='root', passwd='112233', db='dyy',
  1249. charset='utf8')
  1250. cursor = con.cursor() # 使用cursor()方法获取操作游标
  1251. sql = "UPDATE table_schedule SET schedule_price = '%s', schedule_time = '%s', movie_id = '%s',hall_id ='%s',schedule_movie ='%s' \
  1252. WHERE movie_id = '%s'" % (
  1253. self.var_daoyan.get(), self.var_zhuyan.get(), self.movie_id, self.var_jianjie.get(),self.var_name.get(),self.var_id.get()) # SQL 插入语句
  1254. try:
  1255. cursor.execute(sql) # 执行sql语句
  1256. con.commit() # 提交到数据库执行
  1257. messagebox.showinfo('提示!', '更新成功!')
  1258. except:
  1259. con.rollback() # 发生错误时回滚
  1260. messagebox.showinfo('警告!', '更新失败,数据库连接失败!')
  1261. con.close() # 关闭数据库连接
  1262. id_index = self.id.index(self.row_info[0])
  1263. self.name[id_index] = self.var_name.get()
  1264. self.zhuyan[id_index] = self.var_zhuyan.get()
  1265. self.daoyan[id_index] = self.var_daoyan.get()
  1266. self.jianjie[id_index]=self.var_jianjie.get()
  1267. self.tree.item(self.tree.selection()[0], values=(
  1268. self.var_id.get(), self.var_name.get(), self.var_zhuyan.get(),
  1269. self.var_daoyan.get(),self.var_jianjie.get())) # 修改对于行信息
  1270. else:
  1271. messagebox.showinfo('警告!', '不能修改订单号!')
  1272. def del_row(self):
  1273. res = messagebox.askyesnocancel('警告!', '是否删除所选数据?')
  1274. if res == True:
  1275. print(self.row_info[0]) # 鼠标选中的学号
  1276. print(self.tree.selection()[0]) # 行号
  1277. print(self.tree.get_children()) # 所有行
  1278. # 打开数据库连接
  1279. con = pymysql.connect(host='localhost', port=3306, user='root', passwd='112233', db='dyy',
  1280. charset='utf8')
  1281. cursor = con.cursor() # 使用cursor()方法获取操作游标
  1282. sql = "DELETE FROM table_schedule WHERE schedule_id = '%s'" % (self.row_info[0]) # SQL 插入语句
  1283. try:
  1284. cursor.execute(sql) # 执行sql语句
  1285. con.commit() # 提交到数据库执行
  1286. messagebox.showinfo('提示!', '删除成功!')
  1287. except:
  1288. con.rollback() # 发生错误时回滚
  1289. messagebox.showinfo('警告!', '删除失败,数据库连接失败!')
  1290. con.close() # 关闭数据库连接
  1291. id_index = self.id.index(self.row_info[0])
  1292. print(id_index)
  1293. del self.id[id_index]
  1294. del self.name[id_index]
  1295. del self.zhuyan[id_index]
  1296. del self.daoyan[id_index]
  1297. del self.jianjie[id_index]
  1298. del self.movie_id[id_index]
  1299. print(self.id)
  1300. self.tree.delete(self.tree.selection()[0]) # 删除所选行
  1301. print(self.tree.get_children())
  1302. win = tk.Tk()
  1303. beginpage(win)

 

 

 

 

 

 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/124853
推荐阅读
相关标签
  

闽ICP备14008679号