• 【Python订票系统】这才是看电影选座的正确方法,原来我们都上当了~(选座位、一键购票)


    导语

    哈喽哈喽!我是木木子,已经断更很久啦!忙碌很长一段时间了,现在告一段落。

    后续会陆续更新,希望大家能够多多支持我!啾咪.jpg

    2022年扬帆起航,持续为大家输出更多喜欢的内容,分享小编的学习到的知识给大家!

    所有文章完整的素材+源码都在👇👇

    🎁🎁🎁🎁🎁🎁文末自取哦🎁🎁🎁🎁🎁🎁

    PS:“天上的每一颗星,都是爱过我们的人。”

    不要太过惋惜亲人的离去,因为早晚有一天我们会在天上重逢。

    在人间活着的日子,我们都有一个归期,而那些逝去的人,会希望我们好好地活下去。          

                                                                                      ——【人生大事】 

    我爱这离合悲欢,爱这烟火人间,电影《人生大事》将于6月24日上映。

    很多人期待的电影点映不知道有人去看了没?小编刚好卡点去了第一场,这是一部笑着笑着就

    哭了的电影。  之后要看的小伙伴儿记得带点儿纸巾哈。

    今天小编是看了电影之后有感而发撒,代码源于生活今天小编就教大家写一款电影院选票系

    统给大家。想看的小朋友可以这周天去看看,真不错👍

    正文

    一、准备中

    1)环境安装

    本文是基于tkinter的界面化小程序!初级版本写的一个简单的选票系统哈。

    小编使用的环境:Python3、Pycharm社区版、tkinter、turtle、Pillow模块,部分自

    带模块不展示。(不会安装的:小编会发给你们新手大礼包,包括安装包、视频、解答

    疑问可以找我哈戳文末)

     模块安装:pip install -i https://pypi.douban.com/simple/+模块名 

    2)素材准备

    电影院座位是用Turtle绘制完成的。电影院的购票界面是Tkinter写的。

    座位背景👇

    界面电影选项素材(自选:小编随便找的几部截图的哈)话说下面的我还看过几部呢~

    二、代码展示

    1)制作选票系统界面、按钮等等。

    1. import tkinter as tk
    2. from PIL import Image
    3. from PIL import ImageTk
    4. import turtle
    5. from tkinter import messagebox
    6. from cinemaclass import Movie as M
    7. def mainGui(x, y, z):
    8. image = Image.open(x)
    9. photo = ImageTk.PhotoImage(image)
    10. label = tk.Label(image=photo, width=300, height=300)
    11. label.image = photo
    12. label.place(relx=y, rely=z)
    13. window = tk.Tk()
    14. moives = []
    15. lst = []
    16. for i in range(1, 9):
    17. moives.append(M(str(i)))
    18. def xuanpiao(x):
    19. global window, moives
    20. window1 = tk.Tk()
    21. window1.geometry('1330x700')
    22. click = ()
    23. def callback(event):
    24. # print("clicked at:", event.x, event.y) # 打印出该事件(按下鼠标)的x,y轴
    25. # 打印出该事件(按下鼠标)的x,y轴
    26. s = (event.x, event.y) # 把它写到一个元组里
    27. x, y = s
    28. if (160 <= x <= 760) and (100 <= y <= 550):
    29. global click, lst
    30. row = int((x - 160) / 60)
    31. col = int((y - 100) / 45)
    32. click = (col + 1, row + 1)
    33. print(lst)
    34. if movie.isbook(col + 1, row + 1) == False:
    35. lst.append(click)
    36. drawp(canva, movie, lst)
    37. else:
    38. messagebox.showinfo("该位置已购买!")
    39. def yyyyyyyyyyyyyy(num):
    40. global moives
    41. mo = moives[x]
    42. if num == 0:
    43. global lst
    44. sp = '是否购买'
    45. if lst == []:
    46. messagebox.showinfo("请选座!")
    47. return None
    48. for l in lst:
    49. col, row = l
    50. sp += f'{col}{row}列 '
    51. sp += "的座位?"
    52. y = messagebox.askyesno("确认", sp)
    53. if y:
    54. for l in lst:
    55. col, row = l
    56. mo.book(col, row)
    57. mo.save('data')
    58. lst=[]
    59. window1.destroy()
    60. else:
    61. lst = []
    62. drawp(canva, movie, [], lst)
    63. lst = []
    64. window1.destroy()
    65. b2 = tk.Button(window1, text='确认购座', font=('楷书', 12), command=lambda: yyyyyyyyyyyyyy(0))
    66. b2.pack(side=tk.LEFT)
    67. b2 = tk.Button(window1, text='返回', font=('楷书', 12), command=lambda: yyyyyyyyyyyyyy(1))
    68. b2.pack(side=tk.LEFT)
    69. window1.bind("<Button-1>", callback)
    70. if x == 1:
    71. window1.title('电影《你的世界如果没有我》请选择座位')
    72. elif x == 2:
    73. window1.title('电影《只要你过得比我好》请选择座位')
    74. elif x == 3:
    75. window1.title('电影《扬名立万》请选择座位')
    76. elif x == 4:
    77. window1.title('电影《梅艳芳》请选择座位')
    78. elif x == 5:
    79. window1.title('电影《笨鸟大冒险》请选择座位')
    80. elif x == 6:
    81. window1.title('电影《古董局中局》请选择座位')
    82. elif x == 7:
    83. window1.title('电影《长津湖》请选择座位')
    84. else:
    85. window1.title('电影《门锁》请选择座位')
    86. movie = moives[x]
    87. def drawp(canva, moive: M, lst=None, lst2=None):
    88. if lst == None:
    89. lst = []
    90. if lst2 == None:
    91. lst2 = []
    92. from turtle import Shape
    93. theScreen = turtle.TurtleScreen(canva)
    94. t = turtle.RawTurtle(theScreen, visible=True)
    95. s = Shape("compound")
    96. poly2 = ((-20, -10), (-30, -10), (-30, 15), (30, 15), (30, -10), (20, -10))
    97. s.addcomponent(poly2, "pink", "black")
    98. poly1 = (
    99. (0, 0), (10, 0), (10, -10), (20, -10), (20, -30), (-20, -30), (-20, -10), (-10, -10), (-10, 0), (0, 0),)
    100. s.addcomponent(poly1, "white", "black")
    101. theScreen.register_shape("myshape1", s)
    102. s2 = Shape("compound")
    103. # poly2 = ((-10.0, -5.0), (-15.0, -5.0), (-15.0, 7.5), (15.0, 7.5), (15.0, -5.0), (10.0, -5.0))
    104. s2.addcomponent(poly2, "white", "black")
    105. # poly1 = ((0.0, 0.0), (5.0, 0.0), (5.0, -5.0), (10.0, -5.0), (10.0, -15.0), (-10.0, -15.0), (-10.0, -5.0), (-5.0, -5.0), (-5.0, 0.0), (0.0, 0.0))
    106. s2.addcomponent(poly1, "red", "black")
    107. theScreen.register_shape("myshape2", s2)
    108. s3 = Shape("compound")
    109. # poly2 = ((-10.0, -5.0), (-15.0, -5.0), (-15.0, 7.5), (15.0, 7.5), (15.0, -5.0), (10.0, -5.0))
    110. s3.addcomponent(poly2, "white", "black")
    111. # poly1 = ((0.0, 0.0), (5.0, 0.0), (5.0, -5.0), (10.0, -5.0), (10.0, -15.0), (-10.0, -15.0), (-10.0, -5.0), (-5.0, -5.0), (-5.0, 0.0), (0.0, 0.0))
    112. s3.addcomponent(poly1, "green", "black")
    113. theScreen.register_shape("myshape3", s3)
    114. t.settiltangle(270)
    115. t.penup()
    116. t.ht()
    117. t.speed(10)
    118. moive.show()
    119. ##############
    120. ###############
    121. for j in range(10):
    122. for k in range(10):
    123. if (k + 1, j + 1) in lst:
    124. print('green:', lst)
    125. t.shape('myshape3')
    126. else:
    127. if ((k + 1, j + 1) in lst2) or moive.isbook(k + 1, j + 1):
    128. t.shape('myshape2')
    129. else:
    130. t.shape('myshape1')
    131. x = j * 60
    132. y = -k * 45
    133. t.goto(x, y)
    134. t.stamp()
    135. # theScreen.mainloop()
    136. canva = tk.Canvas(window1, relief=tk.FLAT)
    137. canva.pack(fill='both', expand='yes')
    138. drawp(canva, movie, )
    139. window1.mainloop()
    140. # aa = tk.Button(window1, text="Draw", command= lambda: drawp())
    141. # aa.pack()
    142. def chushi_jiemian():
    143. global window
    144. window.title('电影选座系统')
    145. window.geometry('1330x700')
    146. l = tk.Label(window, text='正在热映(8部)', fg='red', font=('楷书', 20), width=30, height=2)
    147. l.place(relx=0.37, rely=0.01)
    148. mainGui(r'你的世界如果没有我.jpg', 0.1, 0.1)
    149. mainGui(r'只要你过的比我好.jpg', 0.3, 0.1)
    150. mainGui(r'扬名立万.jpg', 0.5, 0.1)
    151. mainGui(r'梅艳芳.jpg', 0.7, 0.1)
    152. mainGui(r'笨鸟大冒险.jpg', 0.1, 0.5)
    153. mainGui(r'古董局中局.jpg', 0.3, 0.5)
    154. mainGui(r'长津湖.jpg', 0.5, 0.5)
    155. mainGui(r'门锁.jpg', 0.7, 0.5)
    156. b1 = tk.Button(window, text='点击购票', font=('楷书', 12), command=lambda: xuanpiao(1))
    157. b1.place(relx=0.165, y=350, height=20, relwidth=0.1)
    158. b2 = tk.Button(window, text='点击购票', font=('楷书', 12), command=lambda: xuanpiao(2))
    159. b2.place(relx=0.365, y=350, height=20, relwidth=0.1)
    160. b3 = tk.Button(window, text='点击购票', font=('楷书', 12), command=lambda: xuanpiao(3))
    161. b3.place(relx=0.565, y=350, height=20, relwidth=0.1)
    162. b4 = tk.Button(window, text='点击购票', font=('楷书', 12), command=lambda: xuanpiao(4))
    163. b4.place(relx=0.765, y=350, height=20, relwidth=0.1)
    164. b5 = tk.Button(window, text='点击购票', font=('楷书', 12), command=lambda: xuanpiao(5))
    165. b5.place(relx=0.165, y=635, height=20, relwidth=0.1)
    166. b6 = tk.Button(window, text='点击购票', font=('楷书', 12), command=lambda: xuanpiao(6))
    167. b6.place(relx=0.365, y=635, height=20, relwidth=0.1)
    168. b7 = tk.Button(window, text='点击购票', font=('楷书', 12), command=lambda: xuanpiao(7))
    169. b7.place(relx=0.565, y=635, height=20, relwidth=0.1)
    170. b8 = tk.Button(window, text='点击购票', font=('楷书', 12), command=lambda: xuanpiao(8))
    171. b8.place(relx=0.765, y=635, height=20, relwidth=0.1)
    172. window.mainloop()
    173. chushi_jiemian()

    2)绘制turtle购票之后的电影院座位。

    1. import turtle as t
    2. def goto(x, y):
    3. t.penup()
    4. t.goto(x, y)
    5. t.pendown()
    6. def seat(x, y,):
    7. t.pensize(1)
    8. t.color('black')
    9. for i in range(10):
    10. for j in range(10):
    11. goto(-50 + i * 40, -50 + j * 40)
    12. t.left(90)
    13. t.fd(10)
    14. t.right(90)
    15. t.fd(20)
    16. t.right(90)
    17. t.fd(10)
    18. t.right(90)
    19. t.fd(5)
    20. t.left(90)
    21. t.fd(10)
    22. t.right(90)
    23. t.fd(10)
    24. t.right(90)
    25. t.fd(10)
    26. t.left(90)
    27. t.fd(5)
    28. t.fd(5)
    29. t.left(90)
    30. t.fd(15)
    31. t.left(90)
    32. t.fd(30)
    33. t.left(90)
    34. t.fd(15)
    35. t.left(90)
    36. t.fd(10)
    37. t.right(180)
    38. goto(350, 450)
    39. t.left(90)
    40. t.fd(10)
    41. t.right(90)
    42. t.fd(20)
    43. t.right(90)
    44. t.fd(10)
    45. t.right(90)
    46. t.fd(5)
    47. t.left(90)
    48. t.fd(10)
    49. t.right(90)
    50. t.fd(10)
    51. t.right(90)
    52. t.fd(10)
    53. t.left(90)
    54. t.fd(5)
    55. t.fd(5)
    56. t.left(90)
    57. t.fd(15)
    58. t.left(90)
    59. t.fd(30)
    60. t.left(90)
    61. t.fd(15)
    62. t.left(90)
    63. t.fd(10)
    64. t.left(180)
    65. t.pencolor('white')
    66. goto(-50 + (x-1) * 40, -50 + (y-1) * 40)
    67. t.left(90)
    68. t.fd(10)
    69. t.right(90)
    70. t.fd(20)
    71. t.right(90)
    72. t.fd(10)
    73. t.right(90)
    74. t.fd(5)
    75. t.left(90)
    76. t.fd(10)
    77. t.right(90)
    78. t.fd(10)
    79. t.right(90)
    80. t.fd(10)
    81. t.left(90)
    82. t.fd(5)
    83. t.fd(5)
    84. t.left(90)
    85. t.fd(15)
    86. t.left(90)
    87. t.fd(30)
    88. t.left(90)
    89. t.fd(15)
    90. t.left(90)
    91. t.fd(10)
    92. t.left(180)
    93. t.pencolor('black')
    94. goto(-50 + (x-1) * 40, -50 + (y-1) * 40)
    95. t.fillcolor('red')
    96. t.begin_fill()
    97. t.left(90)
    98. t.fd(10)
    99. t.right(90)
    100. t.fd(20)
    101. t.right(90)
    102. t.fd(10)
    103. t.right(90)
    104. t.fd(5)
    105. t.left(90)
    106. t.fd(10)
    107. t.right(90)
    108. t.fd(10)
    109. t.right(90)
    110. t.fd(10)
    111. t.left(90)
    112. t.fd(5)
    113. t.end_fill()
    114. t.fillcolor('pink')
    115. t.begin_fill()
    116. t.fd(5)
    117. t.left(90)
    118. t.fd(15)
    119. t.left(90)
    120. t.fd(30)
    121. t.left(90)
    122. t.fd(15)
    123. t.left(90)
    124. t.fd(10)
    125. t.left(90)
    126. t.fd(10)
    127. t.right(90)
    128. t.fd(10)
    129. t.right(90)
    130. t.fd(10)
    131. t.left(90)
    132. t.fd(5)
    133. t.end_fill()
    134. t.left(180)
    135. t.ht()
    136. t.tracer(False)
    137. seat(2, 1)
    138. t.done()

    这款电影院选票系统主要就分为这两大块内容。简单的界面购票选票的都完成啦!

    ​三、效果展示

    1)界面效果

    2)点击“长津湖”选座界面:

    3)选座

    4)购票成功

    ​总结

    好啦!到这里这款电影选座购票系统就写完啦!虽然只是一款简单的界面小程序,但是该有的

    效果还是都有滴啦!有大佬也可以自行优化嘻嘻!

    老规矩啦源码文末免费拿,放心 都有哈!拿源码之前记得给我三连一下啦~非常感谢大家!

    🎯完整的免费源码领取处:找我吖!文末可得自行领取,滴滴我也可!

    🎉往期部分文章推荐——

    项目1.3 视频播放器

    用了都说好的Python专属无广告视频播放器,良心到想为它疯狂打call

    项目2.7 刮刮卡小程序

    周末老板请吃东西,刮到多少算多少?Python带你制作一款刮刮卡小程序。

    项目3.2 自动换壁纸

    【Python高级技能】超炫酷,电脑每天自动换壁纸,这个神器适合你。

    项目3.3 艺术字签名

    【艺术字签名生成器】】试卷家长签字居然被嫌弃了|“我觉得我还能再抢救一下,你看行嘛?“

    项目 3.9 码住雪景漫天飘雪小程序

    【Python码住雪景小程序】雪景人像最强攻略:让你一下美10倍、美醉了(中国人不骗中国人)

    项目 4.0 GIF制作神奇(斗罗大陆为例)

    【Python神器】推荐这款傻瓜式GIF制作工具,以后别再说不会了(好用到爆~)

    🎄文章汇总——

    项目1.0 Python—2021 |已有文章汇总 | 持续更新,直接看这篇就够了

    (更多内容+源码都在文章汇总哦!!欢迎阅读~)

  • 相关阅读:
    OPENCV实现DNN图像分类
    C++引用内联auto关键字等介绍
    使用PdfSharp从模板生成Pdf文件
    风控中策略规则发现的两种模型方法
    HTML5期末考核大作业:基于Html+Css+javascript的网页制作(化妆品公司网站制作)
    框架篇
    华为云大数据BI赋能企业数字化发展
    python基于django的宠物知识分享网站
    C语言基础-typedef的用法
    Shell Mvn启动SpringBoot项目
  • 原文地址:https://blog.csdn.net/weixin_55822277/article/details/125462030