Bottom Page

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)
Quote
#2
The code is incomplete.
Quote
#3
Yeah I know this is just a part of it
Quote
#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
silly American kah-nig-hit
Quote
#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
Quote
#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.
Quote
#7
you don't want an integer in entry_box1 ?
Quote

Top Page

Forum Jump:


Users browsing this thread: 1 Guest(s)