IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> Python知识库 -> 【Python订票系统】这才是看电影选座的正确方法,原来我们都上当了~(选座位、一键购票) -> 正文阅读

[Python知识库]【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)制作选票系统界面、按钮等等。

import tkinter as tk
from PIL import Image
from PIL import ImageTk
import turtle
from tkinter import messagebox
from cinemaclass import Movie as M


def 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 t


def 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)购票成功

?总结

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

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

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

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

🎉往期部分文章推荐——

项目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 |已有文章汇总 | 持续更新,直接看这篇就够了

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

  Python知识库 最新文章
Python中String模块
【Python】 14-CVS文件操作
python的panda库读写文件
使用Nordic的nrf52840实现蓝牙DFU过程
【Python学习记录】numpy数组用法整理
Python学习笔记
python字符串和列表
python如何从txt文件中解析出有效的数据
Python编程从入门到实践自学/3.1-3.2
python变量
上一篇文章      下一篇文章      查看所有文章
加:2022-06-26 16:52:04  更:2022-06-26 16:53:14 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年5日历 -2024/5/18 16:02:37-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码