Python Forum
Tkinter exception if entries are not filled up
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tkinter exception if entries are not filled up
#1
Hi, he're my request: I want that if all the entries are not filled , the button stays disabled and if not, the button enables. I tried to but I didn't manage it. Could you tell me what's going wrong and how to solve it ? Thanks:


    label1 = Label(Appli,text="Entrez votre nom: ",font=("arial",12,"bold"),bg="#2340B6", fg="white")
    label1.place(x=20, y=100)
    i= StringVar()
    entry_box1= Entry(Appli, textvariable=i, bg="white", width="15")
    entry_box1.place(x=190,y=105)


    label2= Label(Appli,text="Quelle est votre année de naissance? : ",font=("arial",12,"bold"),bg="#2340B6", fg="white")
    label2.place(x=20, y=175)
    k= IntVar()
    entry_box2= Entry(Appli, textvariable=k, bg="white", width="15")
    entry_box2.place(x=340,y=180)


    label3= Label(Appli,text="Quel est votre revenu mensuel sur vos six derniers mois? : ",font=("arial",12,"bold"),bg="#2340B6", fg="white")
    label3.place(x=20, y=255)
    revenu_moyen= IntVar()
    entry_box3= Entry(Appli, textvariable=revenu_moyen, bg="white", width="15")
    entry_box3.place(x=500,y=260)


    label4= Label(Appli,text="Combien de trimestres avez vous cotisé? : ",font=("arial",12,"bold"),bg="#2340B6", fg="white")
    label4.place(x=20, y=335)
    trimestre_cotisés= IntVar()
    entry_box4= Entry(Appli, textvariable=trimestre_cotisés, bg="white", width="15")
    entry_box4.place(x=380,y=340)


    label5= Label(Appli,text="Combien avez vous d'enfants? : ",font=("arial",12,"bold"),bg="#2340B6", fg="white")
    label5.place(x=20, y=410)
    enfants=IntVar()
    entry_box5 = Entry(Appli, textvariable=enfants, bg="white", width="10")
    entry_box5.place(x=300,y=415)







 
    def do_it():
        if i.get() and k.get() and revenu_moyen.get() and trimestre_cotisés.get() and enfants.get()  :
            button["state"]= "normal"
            F= calcul_fonctionnaire(i.get(), k.get(), revenu_moyen.get(), trimestre_cotisés.get(), enfants.get())
            S=int(F)
            G=F*12
            RA=int(G)
    
    
            A= str(i.get())+", ta pension de retraite sera de "+str(S)+"€ par mois, soit de "+str(RA)+"€ par an"
    
            button.destroy()
            label6= Label(Appli,text=A,font=("arial",15,"bold"), fg="white", bg="#2340B6", bd=2, relief=SUNKEN)
            label6.place(x=40, y=500)
        else:
            button["state"]= "disabled"
    




    button= Button(Appli, text="Calculer", width="20", height="3",command=do_it,font=("arial",12,"bold"),bg="white",fg="#2340B6", state="disabled")
    button.place(x=20, y=500)
Reply
#2
The code is incomplete.
Reply
#3
Yeah I know this is just a part of it
Reply
#4
Get faster answers if you provide MREs (Minimal Reproducible Example)s that can simply be copied/pasted/ran and create the same issue you are having a problem with as sometimes the issues is not where you might think it is and code snippets are like shooting in the dark so do yourself a favor provide a MRE so that we can better help you with YOUR issue - remember we are doing you the favor not you doing us a favor so make it easy on us we are busy too
Reply
#5
Understood. Sorry I'll post MREs when it's a long post. Thank you for having taken the time to inform me. Thumbs Up
Reply
#6
from tkinter import *
 
Appli = Tk()
Appli.title("Application de retraite")
Appli.geometry("640x640")
  
  
label1 = Label(Appli,text="Entrez votre nom: ",font=("arial",12,"bold"),bg="#2340B6", fg="white")
label1.place(x=20, y=100)
i= StringVar()
entry_box1= Entry(Appli, textvariable=i, bg="white", width="15")
entry_box1.place(x=190,y=105)
 
 
label2= Label(Appli,text="Quelle est votre année de naissance? : ",font=("arial",12,"bold"),bg="#2340B6", fg="white")
label2.place(x=20, y=175)
k= IntVar()
entry_box2= Entry(Appli, textvariable=k, bg="white", width="15")
entry_box2.place(x=340,y=180)
 
 
label3= Label(Appli,text="Quel est votre revenu mensuel sur vos six derniers mois? : ",font=("arial",12,"bold"),bg="#2340B6", fg="white")
label3.place(x=20, y=255)
revenu_moyen= IntVar()
entry_box3= Entry(Appli, textvariable=revenu_moyen, bg="white", width="15")
entry_box3.place(x=500,y=260)
 
 
label4= Label(Appli,text="Combien de trimestres avez vous cotisé? : ",font=("arial",12,"bold"),bg="#2340B6", fg="white")
label4.place(x=20, y=335)
trimestre_cotisés= IntVar()
entry_box4= Entry(Appli, textvariable=trimestre_cotisés, bg="white", width="15")
entry_box4.place(x=380,y=340)
 
 
label5= Label(Appli,text="Combien avez vous d'enfants? : ",font=("arial",12,"bold"),bg="#2340B6", fg="white")
label5.place(x=20, y=410)
enfants=IntVar()
entry_box5 = Entry(Appli, textvariable=enfants, bg="white", width="10")
entry_box5.place(x=300,y=415)

def verific():
    if not i.get() or i.get().isnumeric() == True:
        button.configure(state = DISABLED)
        Appli.after(1, verific)
    else:
        button.configure(state = NORMAL)
        Appli.after(1, verific)

def do_it():
    print("execute your function here")


button= Button(Appli, text="Calculer", width="20", height="3",command=do_it,font=("arial",12,"bold"),bg="white",fg="#2340B6")
button.place(x=20, y=500)    

verific()
Appli.mainloop()

entry_box1
is verified by this example.
Reply
#7
you don't want an integer in entry_box1 ?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Tkinter callback exception Ben123 2 430 Feb-17-2024, 06:03 PM
Last Post: deanhystad
  button enabled only when all the inputs are filled cybertooth 5 5,390 Oct-22-2021, 10:10 PM
Last Post: deanhystad
  [Tkinter] Tkinter delete values in Entries, when I'm changing the Frame robertoCarlos 11 5,646 Jul-29-2020, 07:13 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020