我正在尝试为一个项目制作座位预订系统。此代码无法显示哪些座位已被占用

Posted

技术标签:

【中文标题】我正在尝试为一个项目制作座位预订系统。此代码无法显示哪些座位已被占用【英文标题】:I am trying to make a seat reservation system for a project . this code isn't able to show which seats are already occupied 【发布时间】:2021-03-17 11:06:03 【问题描述】:

*此代码可帮助您预订座位,但无法显示已占用一次。我无法理解如何存储这些座位并将它们显示为已占用。 在运行此代码之前,请在您的设备上安装 tkinter *

from tkinter import *
def changeColor(btn):
    global c
    # Use your bg argument instead of highlight background
    btn.configure(highlightbackground='#ff0800')  
root=Tk()
root.title("SEATING ARRANGEMENT")
button1=Button(root,text="A1",width=8,command=lambda: changeColor(button1))
button1.grid(row=0,column=0)
button2=Button(root,text="A2",width=8,command=lambda: changeColor(button2))
button2.grid(row=0,column=1)
button3=Button(root,text="B1",width=8,command=lambda: changeColor(button3))
button3.grid(row=1,column=0)
button4=Button(root,text="B2",width=8,command=lambda: changeColor(button4))
button4.grid(row=1,column=1)
button5=Button(root,text="C1",width=8,command=lambda: changeColor(button5))
button5.grid(row=2,column=0)
button6=Button(root,text="C2",width=8,command=lambda: changeColor(button6))
button6.grid(row=2,column=1)
button7=Button(root,text="D1",width=8,command=lambda: changeColor(button7))
button7.grid(row=3,column=0)
button8=Button(root,text="D2",width=8,command=lambda: changeColor(button8))
button8.grid(row=3,column=1)
button9=Button(root,text="E1",width=8,command=lambda: changeColor(button9))
button9.grid(row=4,column=0)
button10=Button(root,text="E2",width=8,command=lambda: changeColor(button10))
button10.grid(row=4,column=1)
button11=Button(root,text="F1",width=8,command=lambda: changeColor(button11))
button11.grid(row=5,column=0)
button12=Button(root,text="F2",width=8,command=lambda: changeColor(button12))
button12.grid(row=5,column=1)
button13=Button(root,text="G1",width=8,command=lambda: changeColor(button13))
button13.grid(row=6,column=0)
button14=Button(root,text="G2",width=8,command=lambda: changeColor(button14))
button14.grid(row=6,column=1)
button15=Button(root,text="H1",width=8,command=lambda: changeColor(button15))
button15.grid(row=7,column=0)
button16=Button(root,text="H2",width=8,command=lambda: changeColor(button16))
button16.grid(row=7,column=1)
button17=Button(root,text="I1",width=8,command=lambda: changeColor(button17))
button17.grid(row=8,column=0)
button18=Button(root,text="I2",width=8,command=lambda: changeColor(button18))
button18.grid(row=8,column=1)
button19=Button(root,text="J1",width=8,command=lambda: changeColor(button19))
button19.grid(row=9,column=0)
button20=Button(root,text="J2",width=8,command=lambda: changeColor(button20))
button20.grid(row=9,column=1)
**#this was to add some space like a corridor on a flight**
label1=Label(root,text="       ",padx=20).grid(row=0,column=2)

button21=Button(root,text="A3",width=8,command=lambda: changeColor(button21))
button21.grid(row=0,column=3,sticky='E')
button22=Button(root,text="A4",width=8,command=lambda: changeColor(button22))
button22.grid(row=0,column=4,sticky='E')
button23=Button(root,text="B3",width=8,command=lambda: changeColor(button23))
button23.grid(row=1,column=3,sticky='E')
button24=Button(root,text="B4",width=8,command=lambda: changeColor(button24))
button24.grid(row=1,column=4,sticky='E')
button25=Button(root,text="C3",width=8,command=lambda: changeColor(button25))
button25.grid(row=2,column=3,sticky='E')
button26=Button(root,text="C4",width=8,command=lambda: changeColor(button26))
button26.grid(row=2,column=4,sticky='E')
button27=Button(root,text="D3",width=8,command=lambda: changeColor(button27))
button27.grid(row=3,column=3,sticky='E')
button28=Button(root,text="D4",width=8,command=lambda: changeColor(button28))
button28.grid(row=3,column=4,sticky='E')
button29=Button(root,text="E3",width=8,command=lambda: changeColor(button29))
button29.grid(row=4,column=3,sticky='E')
button30=Button(root,text="E4",width=8,command=lambda: changeColor(button30))
button30.grid(row=4,column=4,sticky='E')
button31=Button(root,text="F3",width=8,command=lambda: changeColor(button31))
button31.grid(row=5,column=3,sticky='E')
button32=Button(root,text="F4",width=8,command=lambda: changeColor(button32))
button32.grid(row=5,column=4,sticky='E')
button33=Button(root,text="G3",width=8,command=lambda: changeColor(button33))
button33.grid(row=6,column=3,sticky='E')
button34=Button(root,text="G4",width=8,command=lambda: changeColor(button34))
button34.grid(row=6,column=4,sticky='E')
button35=Button(root,text="H3",width=8,command=lambda: changeColor(button35))
button35.grid(row=7,column=3,sticky='E')
button36=Button(root,text="H4",width=8,command=lambda: changeColor(button36))
button36.grid(row=7,column=4,sticky='E')
button37=Button(root,text="I3",width=8,command=lambda: changeColor(button37))
button37.grid(row=8,column=3,sticky='E')
button38=Button(root,text="I4",width=8,command=lambda: changeColor(button38))
button38.grid(row=8,column=4,sticky='E')
button39=Button(root,text="J3",width=8,command=lambda: changeColor(button39))
button39.grid(row=9,column=3,sticky='E')
button40=Button(root,text="J4",width=8,command=lambda: changeColor(button40))
button40.grid(row=9,column=4,sticky='E')

button=Button(root,text="click me!!")
button.grid(row=10,column=0)

root.mainloop()

如果我们可以使用 mysql 来存储选择或占用的按钮,我猜也会有所帮助

【问题讨论】:

请将此代码缩减为minimal reproducible example。我们没有 40 个按钮,只有两三个就足以说明问题了。 【参考方案1】:

我不熟悉MySql,但是你可以存储占用座位的名称如下:

occupied = set()
def changeColor(btn):
    global c
    # Use your bg argument instead of highlight background
    btn.configure(background='#ff0800')
    occupied.add(str(btn))
    print(occupied)

【讨论】:

但这只有在我点击一个按钮后才会起作用。有什么方法可以在不点击任何东西的情况下看到被占用的地方

以上是关于我正在尝试为一个项目制作座位预订系统。此代码无法显示哪些座位已被占用的主要内容,如果未能解决你的问题,请参考以下文章

编辑 HTML 表格后如何刷新它?

剧院座位预订和数据结构?

更改recyclerview中最后几个项目的跨度计数

基于android的图书馆图书借阅座位预订app

软工3.28课堂笔记

将 Javascript 数组转换为 PHP 数组或将其传递给 PHP 文件