Python Forum
[Tkinter] function to handle exception errors
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] function to handle exception errors
#1
Hello;
I created an application with "TKINTER" which works well today according to my weak knowledge since I am a beginner with the PYTHON language (version 3.5) under Windows 10 64 bits.
It prevents me to finalize this version 1 of this application that I would like to develop even better in the near future. here is the sample code of the application that concerns exception errors problem :

def message_erreur():
    if ent_labo_loc.get()==StringVar:
        lb_loc_exception['text']='Erreur, veuillez introduire seulement des chiffres'
        ent_labo_loc.set("")
    else:
        lb_loc_exception['text']=''
     
def afficher_resultat_loc():
 
    try :              
        calcul=20*log10(float(ent_labo_loc.get())/float(entree_ref_loc.get()))
        calcul=round(calcul,3)
        ent_correction_loc.set(calcul)
        ent_labo_loc.set("")
    except :                
        message_erreur()
    finally :
        pass
the function " afficher_resultat_loc() " is attached to the validation button of the mathematical calculation. Here is the code :

#======= bouton de validation de la correction =====
 
bt_loc_validation=Button(loc,
                     text='Valider',
                     bd=14,             
                     relief=RIDGE,
                     font=('arial',16,'bold'),
                     justify='left',
                     command=afficher_resultat_loc)
bt_loc_validation.place(x=420,y=460)
finally I created a text which must be displayed each time we introduce characters instead of numbers by a label whose code is:

#affichage d'un message en cas d'erreur exception
 
lb_loc_exception=Label(loc,text='',
                   fg='red',
                   font=('arial',18,'bold'),
                   justify='left',
                   bg='cadet blue'
                   )
 
lb_loc_exception.place(x=30,y=420)
the text that will be integrated in this label only appears when the user writes characters and must imperatively to be deleted when the use after introduces a decimal number

I hope I have detailed my problem

thanks for the help
Reply


Messages In This Thread
function to handle exception errors - by atlass218 - Aug-15-2018, 10:20 PM

Forum Jump:

User Panel Messages

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