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



*此代码可帮助预订座位,但无法显示已占用的座位。我不明白怎么能把这些座位放起来,并显示它们已经坐满了。在运行此代码*之前,请在您的设备上安装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来存储所选或占用的按钮,我想这也会有帮助

我不熟悉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)

相关内容

  • 没有找到相关文章

最新更新