I need some help with my room booking application

I am working on a conference room application and I need some help with it.

What I have till now:

What I want to code:

When you select the time in the last step, a message box should open with a confirmation of the selected room, day and time.

When you click the OK button it should save the data (room, day and time) in a txt file.

When you click the OK button it should return to a menu with 2 options: Make a reservation and Delete a reservation. I don’t have a menu now. It opens the option Make a reservation immediately.

When you select the same data there should be a notification that says that the room is already booked.

In the Delete a reservation option you should be able to delete the reservation.

Can someone help me with this? I am a beginner.

I am working on a conference room application and I need some help with
it.

What I have till now:
Hastebin: Send and Save Text or Code Snippets for Free | Toptal®

I see that contains Python code. Phew! I feared it was Lua code.

I’ve never used easygui, so my advice is pretty general.
The EasyGUI docs are here:
https://easygui.readthedocs.io/en/master/

What I want to code:
When you select the time in the last step, a message box should open
with a confirmation of the selected room, day and time.

Sounds like you want a ynbox:
https://easygui.readthedocs.io/en/master/tutorial.html#ynbox

When you click the OK button it should save the data (room, day and time) in a txt file.

Based on the result from the ynbox, write this stuff to a file. The
usual form of that is like this in Python:

 with open("my_filename.txt", "w") as f:
     print("something", file=f)
     print("room", room, file=f)
     print("day", day, file=f)
     print("time", time, file=f)

Note in particular the file=f in the print() calls: this causes
print to write to your text file instead of your terminal.

When you click the OK button it should return to a menu with 2 options: Make a reservation and Delete a reservation. I don’t have a menu now. It opens the option Make a reservation immediately.

Notice that your “make a reservation” is itself a menu. So just put some
code ahead of this to use a choicebox offering “make a reservation”
and “delete” in some form. Then put an if-statement around the rest of
the code:

 if the user chose delete:
     ... code to delete goes here ...
 else:
     .... your existing code to make a reservation
     .... continues here

When you select the same data there should be a notification that says
that the room is already booked.

Now the fun begins. You need to have data structures to record that
particular bookings have been made. There are probably a few ways to do
this, but the most direct approach which occurs to me is that a booking
consists of 3 independent things: (room,day,time). If any of these is
different between 2 bookings, the bookings do not conflict.

So I suggest keeping bookings as 3-tuples, exactly as above. A Python
tuple is like a Python list, except that it cannot be changed once
you’ve made it (this will be important).

Python also has a useful set type, for storing collections of things
which must all be different. So you could keep around a set of
bookings, which starts empty:

 bookings = set()

When you have selected all 3 of room, day, time you can make a booking
as a 3-tuple:

 booking = (room, day, time)

and now you can see if it is already taken:

 if booking in bookings:
     .... the booking is already taken ...
 else:
     ... a new valid booking ...
     # record this booking as now taken
     bookings.add(booking)

In the Delete a reservation option you should be able to delete the
reservation.

Python sets have a handy .remove method for removing a set element,
which you would want in the “delete a booking” part of your code.

Can someone help me with this? I am a beginner.

I would start by recording the room, day and time in distinct variables.
You are collecting the user’s choice like this:

 output = choicebox(text, title, rooms1)

Use a variable named room for this:

 room = choicebox(text, title, rooms1)

and so forth for the day and time. That way you have the various
different values in variable with nice names.

Also, you’re offering the user, intially, rooms1 as their choices. But
you’ve got a very long list of if-statements comparing the choice to
various specific rooms, days and times individually. I expect you can
only get a valid room from your choicebox which offers rooms1. So
you may not need to check it - you know it’s a room.

This may mean that you can just go:

 room = choicebox(text, title, rooms1)
 day = choicebox(text, title, days1)
 time = choicebox(text, title, times1)
 booking = (room, day, time)

without much elaboration. See how that plays out.

You might also put in some print() calls to help see what happened:

 room = choicebox(text, title, rooms1)
 print("chose room", room)
 day = choicebox(text, title, days1)
 print("chose day", day)
 time = choicebox(text, title, times1)
 print("chose time", time)
 booking = (room, day, time)

See if this gets you started.

Cheers,
Cameron Simpson cs@cskk.id.au

I have figured out to get a menu with the choicebox before the 3 rooms window opens.

I have used output = msgbox(message1, title, ok_btn_txt) to display a message box after you select the time because the ynbox gives yes & no and I only need OK.

But now I am stuck, when you press OK it should go back to the first menu but I can’t figure out how. I have tried this:

I tried to make a list of the ok_btn_txt:

ok_btn_txt = ["OK"]

output = msgbox(message1, title, ok_btn_txt)

if output = ok_btn_txt[0]:

output = choicebox(message, title, menu1)

I have figured out to get a menu with the choicebox before the 3 rooms
window opens.

I have used output = msgbox(message1, title, ok_btn_txt) to display a message box after you select the time because the ynbox gives yes & no and I only need OK.

Which you use depends on what you want the user to do. A msgbox
displays a message and waits for the user to press “OK” before
continuing. You do not have to assign it to a variable, because it has
no meaningful return value. So you can discard the output= above.

A ynbox is for asking the user a yes/no style question; it returns a
Boolean value (True or False) which you can use to make a decision.

But now I am stuck, when you press OK it should go back to the first menu but I can’t figure out how. I have tried this:

I think something’s missing here.

If your program is supposed to go back to the beginning again you would
normally use a loop. Example:

 finished = False    # you're not done yet
 while not finished:
     ... book a room etc etc ..
     msgbox(message1, title, ok_btn_txt)

This code would book a room, then display a msgbox, then do it all
again, forever. Normally you would offer a way out:

 finished = False    # you're not done yet
 while not finished:
     ... book a room etc etc ..
     if ynbox("Are you finished?"):
         finished = True

which would book a room, then ask if the user is finished using a
ynbox. The return value from the ynbox call is True if the user
chose “yes” and False if the user chose “no”. We use that in the
if-statement, and if it was true we set finished to True. Then
control returns to the top of the loop, where it tests the loop
condition again. Since that condition is the expression not finished,
if the user chose “yes” so the finished=True, the condition will be
false, and the loop will exit. Control will continue with the code below
the loop.

Now, since the only thing that ynbox does is set finished to True
you can shorten things a little:

 finished = False    # you're not done yet
 while not finished:
     ... book a room etc etc ..
     finished = ynbox("Are you finished?")

The ynbox call is just a function call, and its return value can be
assigned directly to a variable, in this case the finished variable.

I tried to make a list of the ok_btn_txt:

ok_btn_txt = ["OK"]
output = msgbox(message1, title, ok_btn_txt)
if output = ok_btn_txt[0]:
output = choicebox(message, title, menu1)

The msgbox expects just a string (eg "OK") for the ok_btn_txt.

BTW, you don’t need to laboriously put things like "OK" in a separate
variable, you can use then directly:

 msgbox("your messgae here", "some title", "OK")

You want the rooms1 variable for things like the choicebox because
it is a list of things you define separately but other values can just
do inline. It should make things easier.

msgbox does not return a value; you do not need the output= above.

You’re testing with a single =. That is for assignment statements,
like:

 x = 3

Testing for equality uses the double equals ==.

You basicly need a loop if you want to repeat code.

Cheers,
Cameron Simpson cs@cskk.id.au

Can you check if I am doing it right? Hastebin: Send and Save Text or Code Snippets for Free | Toptal®

After I click yes it does nothing.

I’ve just run your code here. As you say, after the final “Are you
finished?” prompt it exits. That is because there’s no loop. Your code
goes:

 finished = False
 output = choicebox(text, title, menu1)
 ... many if-statements ...
 finished = ynbox("Are you finished?")

For this to repeat you want it to look like:

 finished = False
 while not finished:
     output = choicebox(text, title, menu1)
     ... many if-statements ...
     finished = ynbox("Are you finished?")

This runs the indented code under the while repeatedly until
finished becomes True.

Cheers,
Cameron Simpson cs@cskk.id.au

Now it goes back to the “main menu” but it doesn’t give a ynbox with finished = ynbox and I tried output = ynbox also but nothing.

Just looking at this, the only time it will ask if you’re finished is if
all the if-statements take their “true” branch i.e. that the user picks
exactly what you hope. This is because each if-statement is indented to
be inside the true path of the preceeding if-statement. And the
“finished?” ynbox call is inside the innermost (last) if-statement.

Also, this code:

 output = ynbox(message, title)
 finished = True

will always set finished to True, regardless of what the user chose
in the ynbox. The return value of the ynbox() call reflects the
yes/no choice of the user. You’ve assigned that to the variable
output, which you’re not using.

If you always want the “finished?” ynbox to run, it needs to be
uncondition (i.e. “always”). That means not inside an if-statement.

So:

 finished = False
 while not finished:
     ... choiceboxes and if-statements ...
     finished = ynbox("finished?")

See that the finished = ynbox("finished?") is at the
outermost/leftmost indentation, the same as the outermost if-statement
etc?

I suggest putting some print() statements in your code at strategic
places to see what’s going on. Eg: at the top of the loop, just before
the “finished?” question, just before a few of the other choicebox
calls. It will help show what’s running and not running, in case that is
unclear. Eg:

 finished = False
 print("before the loop")
 while not finished:
     print("top of loop")
     ... choiceboxes and if-statements ...
     print("ask finished?")
     finished = ynbox("finished?")
 print("after the loop")

Notice that the indent of the print() is the same as the thing about
to happen.

Cheers,
Cameron Simpson cs@cskk.id.au

I have tried it again and it does give me a ynbox but when I press yes it doesn’t loop back.