i'm creating a basic booking page for a test but i cant get the if else statement to work and show a message box when an entry is empty or when the booking is complete, for now every time i click "finish" with values in the entry box i get the message box for when a value is not entered. here is my code:
class Booking():
def __init__(self, parent):
self.gui(parent)
def gui(self, parent):
if parent == 0:
self.w1 = Tk()
self.w1.configure(bg = '#b6d7a8')
self.w1.geometry('550x550')
self.combo = Data(0)
self.check = Data(0)
self.v = StringVar()
self.v.set("")
self.a = StringVar()
self.a.set("")
else:
self.w1 = Frame(parent)
self.w1.configure(bg = '#b6d7a8')
self.w1.place(x = 0, y = 0, width = 550, height = 550)
#widgets for booking page
self.label2 = Label(self.w1, text = "Booking", fg = "#090909", bg = "#da7d30", font = tkinter.font.Font(family = "MS Shell Dlg 2", size = 26), cursor = "arrow", state = "normal")
self.label2.place(x = 110, y = 15, width = 240, height = 82)
self.combo2 = Combobox(self.w1, value = self.combo.amount, font = tkinter.font.Font(family = "MS Shell Dlg 2", size = 8), cursor = "arrow", state = "normal")
self.combo2.place(x = 40, y = 250, width = 360, height = 32)
self.combo2.current(0)
self.button5 = Button(self.w1, text = "Finish booking ", bg = "#da7d30", fg = "#040404", font = tkinter.font.Font(family = "MS Shell Dlg 2", size = 8), cursor = "arrow", state = "normal", command=self.finish)
self.button5.place(x = 430, y = 340, width = 90, height = 42)
self.button5 = Button(self.w1, text = "Cancel booking ", bg = "#da7d30", fg = "#040404", font = tkinter.font.Font(family = "MS Shell Dlg 2", size = 8), cursor = "arrow", state = "normal")
self.button5.place(x = 430, y = 400, width = 90, height = 42)
self.text4 = Entry(self.w1, bg = "#f7f7f7", textvariable=self.v, font = tkinter.font.Font(family = "MS Shell Dlg 2", size = 8), cursor = "arrow", state = "normal")
self.text4.place(x = 40, y = 160, width = 140, height = 40)
self.text6 = Entry(self.w1, bg = "#f7f7f7", textvariable=self.v, font = tkinter.font.Font(family = "MS Shell Dlg 2", size = 8), cursor = "arrow", state = "normal")
self.text6.place(x = 250, y = 330, width = 140, height = 40)
self.text7 = Entry(self.w1, bg = "#f7f7f7", textvariable=self.v, font = tkinter.font.Font(family = "MS Shell Dlg 2", size = 8), cursor = "arrow", state = "normal")
self.text7.place(x = 40, y = 405, width = 240, height = 100)
self.text5 = Entry(self.w1, bg = "#f7f7f7", textvariable=self.v, font = tkinter.font.Font(family = "MS Shell Dlg 2", size = 8), cursor = "arrow", state = "normal")
self.text5.place(x = 40, y = 330, width = 140, height = 40)
self.label3 = Label(self.w1, text = "Date", fg = "#090909", bg = "#da7d30", font = tkinter.font.Font(family = "MS Shell Dlg 2", size = 18), cursor = "arrow", state = "normal")
self.label3.place(x = 40, y = 120)
self.label7 = Label(self.w1, text = "Time", fg = "#090909", bg = "#da7d30", font = tkinter.font.Font(family = "MS Shell Dlg 2", size = 18), cursor = "arrow", state = "normal")
self.label7.place(x = 250, y = 120)
self.combo5 = Combobox(self.w1, value = self.check.time, font = tkinter.font.Font(family = "MS Shell Dlg 2", size = 18), cursor = "arrow", state = "normal")
self.combo5.place(x = 250, y = 160, width = 140, height = 40)
self.combo5.current(0)
self.label3 = Label(self.w1, text = "Amount of people", fg = "#090909", bg = "#da7d30", font = tkinter.font.Font(family = "MS Shell Dlg 2", size = 16), cursor = "arrow", state = "normal")
self.label3.place(x = 40, y = 210)
self.label5 = Label(self.w1, text = "Date", fg = "#090909", bg = "#da7d30", font = tkinter.font.Font(family = "MS Shell Dlg 2", size = 18), cursor = "arrow", state = "normal")
self.label5.place(x = 40, y = 120)
self.label8 = Label(self.w1, text = "First name", fg = "#090909", bg = "#da7d30", font = tkinter.font.Font(family = "MS Shell Dlg 2", size = 18), cursor = "arrow", state = "normal")
self.label8.place(x = 40, y = 290)
self.label9 = Label(self.w1, text = "Last name", fg = "#090909", bg = "#da7d30", font = tkinter.font.Font(family = "MS Shell Dlg 2", size = 18), cursor = "arrow", state = "normal")
self.label9.place(x = 250, y = 290)
self.label9 = Label(self.w1, text = "Comments (optional)", fg = "#090909", bg = "#da7d30", font = tkinter.font.Font(family = "MS Shell Dlg 2", size = 12), cursor = "arrow", state = "normal")
self.label9.place(x = 40, y = 375)
#functions for booking page
def finish(self):
try:
self.v.get()
value = self.v.get()
if (self.v.get() == 0):
messagebox.showinfo(title="Error", message="You must fill out everything!")
elif (self.v.get() ==1):
messagebox.showinfo(title="Booking", message="Your booking has been complete")
self.text4.delete(END)
self.text6.delete(END)
self.text5.delete(END)
except ValueError:
print("")
source https://stackoverflow.com/questions/74061791/how-to-get-my-app-to-show-a-message-box-when-an-entry-field-is-complete-and-when
Comments
Post a Comment