程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

[Python ticket booking system] this is the correct way to choose seats for movies. It turns out that we were all cheated ~ (choose seats and buy tickets with one click)

編輯:Python

Introduction

Hello, hello ! I'm kimiko , It has been broken for a long time ! Busy for a long time , Now it's over .

It will be updated one after another , I hope you can support me more ! Jumi .jpg

2022 Set sail in , Continue to output more favorite content for everyone , Share the knowledge learned by Xiaobian to everyone !

Complete material for all articles + The source code is in

Take it from yourself at the end of the article

PS:“ Every star in the sky , Are people who have loved us .”

Don't feel too sorry for the departure of your loved ones , Because sooner or later we will meet again in the sky .

Living on earth , We all have a return date , And those who died , Would like us to live well .          

                                                                                  ——【 Life events 】 

I love the joys and sorrows of separation , Love this world of fireworks , The movie 《 Life events 》 Will be in 6 month 24 1 .

Many people are looking forward to seeing the movie. I wonder if anyone has gone to see it ? Xiaobian just got stuck in the first scene , This is a movie that laughs and laughs

Crying movies .  Remember to take some paper towels with you when you want to see them later .

Today, Xiao Bian was inspired by the movie , Code comes from life . Today, I will teach you to write a movie theater voting system

Give it to everyone . Children who want to see it can go to see it this Sunday , That's good

Text

One 、 In preparation

1) Environmental installation

This paper is based on tkinter Interface applet ! The primary version of a simple voting system .

The environment used by Xiaobian :Python3、Pycharm Community Edition 、tkinter、turtle、Pillow modular , Partly from

No display with module .( It won't be installed : Xiaobian will give you a novice gift bag , Including installation package 、 video 、 answer

If you have any questions, please contact me at the end of the article )

 Module installation :pip install -i https://pypi.douban.com/simple/+ Module name 

2) Material preparation

The seats in the cinema are Turtle Drawing completed . The ticket purchase interface of the cinema is Tkinter Written .

Seat background

Interface movie options material ( Optional : Xiaobian casually found several screenshots ) I've seen a few of the following ~

Two 、 Code display

1) Make the ballot system interface 、 Buttons, etc .

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) # Print out the event ( Press mouse ) Of x,y Axis
# Print out the event ( Press mouse ) Of x,y Axis
s = (event.x, event.y) # Write it in a tuple
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(" This location has been purchased !")
def yyyyyyyyyyyyyy(num):
global moives
mo = moives[x]
if num == 0:
global lst
sp = ' Whether to buy '
if lst == []:
messagebox.showinfo(" Please choose a seat !")
return None
for l in lst:
col, row = l
sp += f'{col} row {row} Column '
sp += " A seat for ?"
y = messagebox.askyesno(" confirm ", 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=' Confirm the seat purchase ', font=(' Regular script ', 12), command=lambda: yyyyyyyyyyyyyy(0))
b2.pack(side=tk.LEFT)
b2 = tk.Button(window1, text=' return ', font=(' Regular script ', 12), command=lambda: yyyyyyyyyyyyyy(1))
b2.pack(side=tk.LEFT)
window1.bind("<Button-1>", callback)
if x == 1:
window1.title(' The movie 《 Your world without me 》 Please choose a seat ')
elif x == 2:
window1.title(' The movie 《 As long as you live better than me 》 Please choose a seat ')
elif x == 3:
window1.title(' The movie 《 Make a name for yourself 》 Please choose a seat ')
elif x == 4:
window1.title(' The movie 《 Anita Mui 》 Please choose a seat ')
elif x == 5:
window1.title(' The movie 《 Stupid bird adventure 》 Please choose a seat ')
elif x == 6:
window1.title(' The movie 《 Antiques Bureau 》 Please choose a seat ')
elif x == 7:
window1.title(' The movie 《 Changjin Lake 》 Please choose a seat ')
else:
window1.title(' The movie 《 Door lock 》 Please choose a seat ')
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(' Movie seat selection system ')
window.geometry('1330x700')
l = tk.Label(window, text=' Is hit (8 Ministry )', fg='red', font=(' Regular script ', 20), width=30, height=2)
l.place(relx=0.37, rely=0.01)
mainGui(r' Your world without me .jpg', 0.1, 0.1)
mainGui(r' As long as you are better than me .jpg', 0.3, 0.1)
mainGui(r' Make a name for yourself .jpg', 0.5, 0.1)
mainGui(r' Anita Mui .jpg', 0.7, 0.1)
mainGui(r' Stupid bird adventure .jpg', 0.1, 0.5)
mainGui(r' Antiques Bureau .jpg', 0.3, 0.5)
mainGui(r' Changjin Lake .jpg', 0.5, 0.5)
mainGui(r' Door lock .jpg', 0.7, 0.5)
b1 = tk.Button(window, text=' Click to buy tickets ', font=(' Regular script ', 12), command=lambda: xuanpiao(1))
b1.place(relx=0.165, y=350, height=20, relwidth=0.1)
b2 = tk.Button(window, text=' Click to buy tickets ', font=(' Regular script ', 12), command=lambda: xuanpiao(2))
b2.place(relx=0.365, y=350, height=20, relwidth=0.1)
b3 = tk.Button(window, text=' Click to buy tickets ', font=(' Regular script ', 12), command=lambda: xuanpiao(3))
b3.place(relx=0.565, y=350, height=20, relwidth=0.1)
b4 = tk.Button(window, text=' Click to buy tickets ', font=(' Regular script ', 12), command=lambda: xuanpiao(4))
b4.place(relx=0.765, y=350, height=20, relwidth=0.1)
b5 = tk.Button(window, text=' Click to buy tickets ', font=(' Regular script ', 12), command=lambda: xuanpiao(5))
b5.place(relx=0.165, y=635, height=20, relwidth=0.1)
b6 = tk.Button(window, text=' Click to buy tickets ', font=(' Regular script ', 12), command=lambda: xuanpiao(6))
b6.place(relx=0.365, y=635, height=20, relwidth=0.1)
b7 = tk.Button(window, text=' Click to buy tickets ', font=(' Regular script ', 12), command=lambda: xuanpiao(7))
b7.place(relx=0.565, y=635, height=20, relwidth=0.1)
b8 = tk.Button(window, text=' Click to buy tickets ', font=(' Regular script ', 12), command=lambda: xuanpiao(8))
b8.place(relx=0.765, y=635, height=20, relwidth=0.1)
window.mainloop()
chushi_jiemian()

2) draw turtle Cinema seats after ticket purchase .

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()

This cinema voting system is mainly divided into these two parts . The simple interface for purchasing votes has been completed !

​ 3、 ... and 、 Effect display

1) Interface effect

2) Click on “ Changjin Lake ” Seat selection interface :

3) Choose a seat

4) Successful ticket purchase

​ summary

All right. ! Here, the movie seat selection and ticket purchasing system has been completed ! Although it is just a simple interface applet , But there should be

The effect still has drops ! Some big guys can also optimize by themselves !

It's the old rule to get free at the end of the source code , don 't worry All of them ! Remember to give me three times before you get the source code ~ Thank you very much !

Complete free source code collection office : Find me ! At the end of the article, you can get it by yourself , Didi, I can also !

Some previous articles recommend ——

project 1.3 Video player

It's all agreed Python Exclusive ad free video player , Conscience to want to fight crazy for it call

project 2.7 Scratch card applet

The boss invited me to eat at the weekend , Scrape as much as you can ?Python Take you to make a scratch card applet .

project 3.2 Automatic wallpaper change

【Python Advanced skills 】 It's cool , The computer automatically changes the wallpaper every day , This artifact suits you .

project 3.3 WordArt signature

【 WordArt signature generator 】】 The parents' signature of the test paper was rejected |“ I think I can save it again , You see ?“

project 3.9 Code live in the snow all over the sky, snow applet

【Python Code live snow applet 】 The strongest introduction to snow portrait : Let you look beautiful 10 times 、 Mei is drunk ( The Chinese don't lie to the Chinese )

project 4.0 GIF Make magic ( Take Douluo as an example )

【Python Artifact 】 Recommend this fool style GIF Production tools , Don't say it again... No ( Good use of explosion ~)

A summary of the article ——

project 1.0 Python—2021 | Summary of existing articles | Continuous updating , Just read this article directly

( More + The source code is summarized in the article !! Welcome to ~)


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved