1

I haven't seen many people asking this, so I believe I have perhaps attempted to tackle this issue in a bad manner.

Anyway, I am trying to create a seating plan that will allow people to book each seat, however, I'm not sure how I can make it so that each button will indicate a different seating position, without making all the buttons separately, which I want to avoid.

I thought maybe I could make a class for 'building' each seat, but I don't know where to begin.

Here's what I've got so far. It's all under a class, hence the indent.

        seatLayout = Canvas(self.root, width=200, height=100)
        seatLayout.pack()
        # creates 200 buttons
        seat_row_char_list = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J']
        i = 1
        seat_row_char = 'A'
        seat_column_num = 1
        for x in range(10):
            for y in range(1, 21):
                seatMaker = Button(seatLayout, text='%s%d' % (seat_row_char, seat_column_num))
                # this part just makes the grid itself
                seatLayout.grid_rowconfigure(x, weight=1)
                seatLayout.grid_columnconfigure(y, weight=1)
                seatMaker.grid(row=x, column=y, sticky=N + S + E + W, padx=3, pady=3)
                #
                seat_column_num += 1
                if seat_column_num > 20:
                    seat_column_num=1
                else:
                    continue

            seat_row_char = seat_row_char_list[i]
            i += 1

This will show this in tkinter:

Exactly how I want it, but it lacks the button feedback :/

Sorry if there are any mistakes with the formatting, first time actually posting here :)

bandolero
  • 43
  • 5
  • 2
    there was a question about creating seating charts in tkinter just a week or so ago. Does this help? https://stackoverflow.com/q/59901272/7432. There are also plenty of questions about asking for creating buttons in a loop. – Bryan Oakley Jan 30 '20 at 19:41
  • @BryanOakley I've already created the seats, however, I'm looking to make each button run a function that can recognise which seat it is e.g. A1 or H5 – bandolero Jan 30 '20 at 20:04

0 Answers0