Python订票系统这才是看电影选座的正确方法,原来我们都上当了

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

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

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

——【人生大事】

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

很多人期待的电影点映不知道有人去看了没?小编刚好卡点去了第一场,这是一部笑着笑着就哭了的电影。之后要看的小伙伴儿记得带点儿纸巾哈。

今天小编就教大家写一款电影院选票系统给大家。

一、准备中

1)环境安装

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

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

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

2)素材准备

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

座位背景

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

二、代码展示

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

import tkinter as tkfrom PIL import Imagefrom PIL import ImageTkimport turtlefrom tkinter import messageboxfrom cinemaclass import Movie as Mdef mainGui(x, y, z):
    image = Image.open(x)
    photo = ImageTk.PhotoImage(image)
    label = tk.Label(image=photo, width=300, height=300)
    label.image = photo
    label.place(relx=y, rely=z)


window = tk.Tk()

moives = []
lst = []for i in range(1, 9):
    moives.append(M(str(i)))def xuanpiao(x):
    global window, moives

    window1 = tk.Tk()
    window1.geometry('1330x700')
    click = ()    def callback(event):
        # print("clicked at:", event.x, event.y)  # 打印出该事件(按下鼠标)的x,y轴
        # 打印出该事件(按下鼠标)的x,y轴
        s = (event.x, event.y)  # 把它写到一个元组里
        x, y = s        if (160 <= x <= 760) and (100 <= y <= 550):            global click, lst
            row = int((x - 160) / 60)
            col = int((y - 100) / 45)
            click = (col + 1, row + 1)

            print(lst)            if movie.isbook(col + 1, row + 1) == False:
                lst.append(click)
                drawp(canva, movie, lst)            else:
                messagebox.showinfo("该位置已购买!")    def yyyyyyyyyyyyyy(num):
        global moives
        mo = moives[x]        if num == 0:            global lst
            sp = '是否购买'
            if lst == []:
                messagebox.showinfo("请选座!")                return None

            for l in lst:
                col, row = l
                sp += f'{col}排{row}列 '
            sp += "的座位?"
            y = messagebox.askyesno("确认", sp)            if y:                for l in lst:
                    col, row = l
                    mo.book(col, row)
                mo.save('data')
                lst=[]
                window1.destroy()            else:
                lst = []
            drawp(canva, movie, [], lst)
            lst = []
        window1.destroy()

    b2 = tk.Button(window1, text='确认购座', font=('楷书', 12), command=lambda: yyyyyyyyyyyyyy(0))
    b2.pack(side=tk.LEFT)
    b2 = tk.Button(window1, text='返回', font=('楷书', 12), command=lambda: yyyyyyyyyyyyyy(1))
    b2.pack(side=tk.LEFT)
    window1.bind("<Button-1>", callback)    if x == 1:
        window1.title('电影《你的世界如果没有我》请选择座位')    elif x == 2:
        window1.title('电影《只要你过得比我好》请选择座位')    elif x == 3:
        window1.title('电影《扬名立万》请选择座位')    elif x == 4:
        window1.title('电影《梅艳芳》请选择座位')    elif x == 5:
        window1.title('电影《笨鸟大冒险》请选择座位')    elif x == 6:
        window1.title('电影《古董局中局》请选择座位')    elif x == 7:
        window1.title('电影《长津湖》请选择座位')    else:
        window1.title('电影《门锁》请选择座位')

    movie = moives[x]    def drawp(canva, moive: M, lst=None, lst2=None):
        if lst == None:
            lst = []        if lst2 == None:
            lst2 = []        from turtle import Shape
        theScreen = turtle.TurtleScreen(canva)
        t = turtle.RawTurtle(theScreen, visible=True)
        s = Shape("compound")
        poly2 = ((-20, -10), (-30, -10), (-30, 15), (30, 15), (30, -10), (20, -10))
        s.addcomponent(poly2, "pink", "black")
        poly1 = (
        (0, 0), (10, 0), (10, -10), (20, -10), (20, -30), (-20, -30), (-20, -10), (-10, -10), (-10, 0), (0, 0),)
        s.addcomponent(poly1, "white", "black")
        theScreen.register_shape("myshape1", s)
        s2 = Shape("compound")        # 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))
        s2.addcomponent(poly2, "white", "black")        # 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))
        s2.addcomponent(poly1, "red", "black")
        theScreen.register_shape("myshape2", s2)
        s3 = Shape("compound")        # 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))
        s3.addcomponent(poly2, "white", "black")        # 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))
        s3.addcomponent(poly1, "green", "black")
        theScreen.register_shape("myshape3", s3)

        t.settiltangle(270)
        t.penup()
        t.ht()
        t.speed(10)
        moive.show()        ##############

        ###############

        for j in range(10):            for k in range(10):                if (k + 1, j + 1) in lst:
                    print('green:', lst)
                    t.shape('myshape3')                else:                    if ((k + 1, j + 1) in lst2) or moive.isbook(k + 1, j + 1):
                        t.shape('myshape2')                    else:
                        t.shape('myshape1')
                x = j * 60
                y = -k * 45
                t.goto(x, y)
                t.stamp()        # theScreen.mainloop()

    canva = tk.Canvas(window1, relief=tk.FLAT)
    canva.pack(fill='both', expand='yes')
    drawp(canva, movie, )

    window1.mainloop()    # aa = tk.Button(window1, text="Draw", command= lambda: drawp())
    # aa.pack()def chushi_jiemian():
    global window
    window.title('电影选座系统')
    window.geometry('1330x700')
    l = tk.Label(window, text='正在热映(8部)', fg='red', font=('楷书', 20), width=30, height=2)
    l.place(relx=0.37, rely=0.01)
    mainGui(r'你的世界如果没有我.jpg', 0.1, 0.1)
    mainGui(r'只要你过的比我好.jpg', 0.3, 0.1)
    mainGui(r'扬名立万.jpg', 0.5, 0.1)
    mainGui(r'梅艳芳.jpg', 0.7, 0.1)
    mainGui(r'笨鸟大冒险.jpg', 0.1, 0.5)
    mainGui(r'古董局中局.jpg', 0.3, 0.5)
    mainGui(r'长津湖.jpg', 0.5, 0.5)
    mainGui(r'门锁.jpg', 0.7, 0.5)
    b1 = tk.Button(window, text='点击购票', font=('楷书', 12), command=lambda: xuanpiao(1))
    b1.place(relx=0.165, y=350, height=20, relwidth=0.1)
    b2 = tk.Button(window, text='点击购票', font=('楷书', 12), command=lambda: xuanpiao(2))
    b2.place(relx=0.365, y=350, height=20, relwidth=0.1)
    b3 = tk.Button(window, text='点击购票', font=('楷书', 12), command=lambda: xuanpiao(3))
    b3.place(relx=0.565, y=350, height=20, relwidth=0.1)
    b4 = tk.Button(window, text='点击购票', font=('楷书', 12), command=lambda: xuanpiao(4))
    b4.place(relx=0.765, y=350, height=20, relwidth=0.1)
    b5 = tk.Button(window, text='点击购票', font=('楷书', 12), command=lambda: xuanpiao(5))
    b5.place(relx=0.165, y=635, height=20, relwidth=0.1)
    b6 = tk.Button(window, text='点击购票', font=('楷书', 12), command=lambda: xuanpiao(6))
    b6.place(relx=0.365, y=635, height=20, relwidth=0.1)
    b7 = tk.Button(window, text='点击购票', font=('楷书', 12), command=lambda: xuanpiao(7))
    b7.place(relx=0.565, y=635, height=20, relwidth=0.1)
    b8 = tk.Button(window, text='点击购票', font=('楷书', 12), command=lambda: xuanpiao(8))
    b8.place(relx=0.765, y=635, height=20, relwidth=0.1)
    window.mainloop()


chushi_jiemian()

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

import turtle as tdef goto(x, y):    t.penup()    t.goto(x, y)    t.pendown()def seat(x, y,):    t.pensize(1)    t.color('black')    for i in range(10):        for j in range(10):            goto(-50 + i * 40, -50 + j * 40)            t.left(90)            t.fd(10)            t.right(90)            t.fd(20)            t.right(90)            t.fd(10)            t.right(90)            t.fd(5)            t.left(90)            t.fd(10)            t.right(90)            t.fd(10)            t.right(90)            t.fd(10)            t.left(90)            t.fd(5)            t.fd(5)            t.left(90)            t.fd(15)            t.left(90)            t.fd(30)            t.left(90)            t.fd(15)            t.left(90)            t.fd(10)            t.right(180)    goto(350, 450)    t.left(90)    t.fd(10)    t.right(90)    t.fd(20)    t.right(90)    t.fd(10)    t.right(90)    t.fd(5)    t.left(90)    t.fd(10)    t.right(90)    t.fd(10)    t.right(90)    t.fd(10)    t.left(90)    t.fd(5)    t.fd(5)    t.left(90)    t.fd(15)    t.left(90)    t.fd(30)    t.left(90)    t.fd(15)    t.left(90)    t.fd(10)    t.left(180)    t.pencolor('white')    goto(-50 + (x-1) * 40, -50 + (y-1) * 40)    t.left(90)    t.fd(10)    t.right(90)    t.fd(20)    t.right(90)    t.fd(10)    t.right(90)    t.fd(5)    t.left(90)    t.fd(10)    t.right(90)    t.fd(10)    t.right(90)    t.fd(10)    t.left(90)    t.fd(5)    t.fd(5)    t.left(90)    t.fd(15)    t.left(90)    t.fd(30)    t.left(90)    t.fd(15)    t.left(90)    t.fd(10)    t.left(180)    t.pencolor('black')    goto(-50 + (x-1) * 40, -50 + (y-1) * 40)    t.fillcolor('red')    t.begin_fill()    t.left(90)    t.fd(10)    t.right(90)    t.fd(20)    t.right(90)    t.fd(10)    t.right(90)    t.fd(5)    t.left(90)    t.fd(10)    t.right(90)    t.fd(10)    t.right(90)    t.fd(10)    t.left(90)    t.fd(5)    t.end_fill()    t.fillcolor('pink')    t.begin_fill()    t.fd(5)    t.left(90)    t.fd(15)    t.left(90)    t.fd(30)    t.left(90)    t.fd(15)    t.left(90)    t.fd(10)    t.left(90)    t.fd(10)    t.right(90)    t.fd(10)    t.right(90)    t.fd(10)    t.left(90)    t.fd(5)    t.end_fill()    t.left(180)t.ht()t.tracer(False)seat(2, 1)t.done()

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

三、效果展示

1)界面效果

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

3)选座

4)购票成功

总结

好啦!到这里这款电影选座购票系统就写完啦!虽然只是一款简单的界面小程序,但是该有的效果还是都有滴啦!有大佬也可以自行优化!

-END-

猜你喜欢

转载自blog.csdn.net/qiqi1220/article/details/125563272