Skip to main content

how to get my app to show a message box when an entry field is complete and when it's empty?

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

Popular posts from this blog

Where and how is this Laravel kernel constructor called? [closed]

Where and how is this Laravel kernel constructor called? public fucntion __construct(Application $app, $Router $roouter) { } I have read the documentation and some online tutorial but I can find any clear explanation. I am learning Laravel and I am wondering where does this kernel constructor receives its arguments from. "POSTMOTERM" CLARIFICATION: Here is more clarity.I have checked the boostrap/app.php and it is only used for boostrapping the interfaces into the container class. What is not clear to me is where and how the Kernel class is instatiated and the arguments passed to the object calling the constructor.Something similar to; obj = new kernel(arg1,arg2) or, is the framework using some magic functions somewhere? Special gratitude to those who burn their eyeballs and brain cells on this trivia before it goes into a full blown menopause alias "MARKED AS DUPLICATE". To some of the itchy-finger keyboard warriors, a.k.a The mods,because I believe in th...

Why is my reports service not connecting?

I am trying to pull some data from a Postgres database using Node.js and node-postures but I can't figure out why my service isn't connecting. my routes/index.js file: const express = require('express'); const router = express.Router(); const ordersCountController = require('../controllers/ordersCountController'); const ordersController = require('../controllers/ordersController'); const weeklyReportsController = require('../controllers/weeklyReportsController'); router.get('/orders_count', ordersCountController); router.get('/orders', ordersController); router.get('/weekly_reports', weeklyReportsController); module.exports = router; My controllers/weeklyReportsController.js file: const weeklyReportsService = require('../services/weeklyReportsService'); const weeklyReportsController = async (req, res) => { try { const data = await weeklyReportsService; res.json({data}) console...

How to show number of registered users in Laravel based on usertype?

i'm trying to display data from the database in the admin dashboard i used this: <?php use Illuminate\Support\Facades\DB; $users = DB::table('users')->count(); echo $users; ?> and i have successfully get the correct data from the database but what if i want to display a specific data for example in this user table there is "usertype" that specify if the user is normal user or admin i want to user the same code above but to display a specific usertype i tried this: <?php use Illuminate\Support\Facades\DB; $users = DB::table('users')->count()->WHERE usertype =admin; echo $users; ?> but it didn't work, what am i doing wrong? source https://stackoverflow.com/questions/68199726/how-to-show-number-of-registered-users-in-laravel-based-on-usertype