Python Forum

Full Version: improved application becomes non-functional
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello;
For information I am beginner with regard to the programming with the language "PYTHON". I just created a simplified application for the moment with the widgets (Frame Menu) that work properly as I wish with a very high number of lines. For that, I opt to perfect it to reduce its volume by modifying the function (faire_apparaitre)
By running the program no bug mentioned but the color change for the frames by clicking on the submenu of the tab (ILS) does not change the color of the background of each frame as what happens for the application voluminous. Here is the code of the large application (which works perfectly):

#coding:utf-8
  
from tkinter import *
  
############################################
# fonction pour faire basculer l'affichage #
# des frames : ILS_35L , ILS_35R , ILS_17R #
############################################
def faire_apparaitre(frame):
    global fen
        
    #pour faire apparaitre la frame (GP_35R)   
    if frame!=loc_35L and frame!=loc_17R and frame!=loc_35R and frame!=gp_17R  and frame != gp_35L :
        loc_35L.grid_forget()
        loc_35R.grid_forget()
        loc_17R.grid_forget()
        gp_35L.grid_forget()       
        gp_17R.grid_forget()         
        gp_35R.grid()
         
    #pour faire apparaitre la frame (gp_35L)   
    elif frame!=loc_35L and frame!=loc_17R and frame!=loc_35R and frame!=gp_17R  and frame != gp_35R :
        loc_35L.grid_forget()
        loc_35R.grid_forget()
        loc_17R.grid_forget()
        gp_35R.grid_forget()       
        gp_17R.grid_forget()       
        gp_35L.grid()
         
    #pour faire apparaitre la frame (gp_17R)   
    elif frame!=loc_35L and frame!=loc_17R and frame!=loc_35R and frame!=gp_35L  and frame != gp_35R :
        loc_35L.grid_forget()
        loc_35R.grid_forget()
        loc_17R.grid_forget()
        gp_35L.grid_forget()       
        gp_35R.grid_forget()
        gp_17R.grid()
         
    #pour faire apparaitre la frame (loc_35L)
    elif frame!=gp_35L and frame!=loc_17R and frame!=loc_35R and frame!=gp_17R  and frame != gp_35R :       
        loc_35R.grid_forget()
        loc_17R.grid_forget()
        gp_17R.grid_forget()
        gp_35L.grid_forget()       
        gp_35R.grid_forget()           
        loc_35L.grid()
     
    #pour faire apparaitre la frame (LOC_35R)
    elif frame!=gp_35L and frame!=loc_17R and frame!=loc_35L and frame!=gp_17R  and frame != gp_35R :
          
        loc_35L.grid_forget()
        loc_17R.grid_forget()
        gp_17R.grid_forget()
        gp_35L.grid_forget()       
        gp_35R.grid_forget()       
        loc_35R.grid()
         
    #pour faire apparaitre la frame (loc_17R)          
    else:             
        loc_35L.grid_forget()
        loc_35R.grid_forget()
        gp_17R.grid_forget()
        gp_35L.grid_forget()       
        gp_35R.grid_forget()   
        loc_17R.grid()
         
    fen.update()
 
 
     
###################################################
# fonction pour faire disparaitre l'image de fond #
###################################################
 
def supprimer_lb_image ():
    global lb_image
         
    if lb_image!=None:
        lb_image.destroy()
        lb_image=None
    else:
        pass
#######################################
#             IMPORTANT (affichage des pages [loc,gp])
##########################################
 
# afficher le contenu de la page (loc_35L)
def afficher_loc_35L():
    supprimer_lb_image ()#je supprime l'image pour afficher les frames
    faire_apparaitre(loc_35L)
 
# afficher le contenu de la page (loc_35R) 
def afficher_loc_35R():
    supprimer_lb_image ()
    faire_apparaitre(loc_35R)
 
     
# afficher le contenu de la page (loc_17R)   
def afficher_loc_17R():
    supprimer_lb_image () #je supprime l'image pour afficher les frames
    faire_apparaitre(loc_17R)
 
 
# afficher le contenu de la page (gp_35L)
def afficher_gp_35L():
    supprimer_lb_image ()#je supprime l'image pour afficher les frames
    faire_apparaitre(gp_35L)
    
# afficher le contenu de la page (gp_35R)
def afficher_gp_35R():
    supprimer_lb_image ()
    faire_apparaitre(gp_35R)
        
# afficher le contenu de la page (gp_17R)  
def afficher_gp_17R():
    supprimer_lb_image () #je supprime l'image pour afficher les frames
    faire_apparaitre(gp_17R)
        
     
def donothing():
   filewin = Toplevel(fen)
   button = Button(filewin, text="Do nothing button")
   button.grid()
     
def quitter():
    fen.destroy()
     
####################################
# A propos de l'application : Info #
####################################
     
def info_de_application():
    info=Toplevel(fen)
    info.title('A propos de l\'application')
    lb1=Label(
    info,
    font=('tahoma', 13, 'bold'),
    fg='black', padx=15,
    text='\nCette application a été conçue pour effectuer\nla correction demandée par l\'avion LABO\ndurant le contrôle en vol, de la ddm du signal\nrayonné par rapport à la ddm exigée par \nl\'avion LABO.\n',
    justify='left')
    lb1.grid()
    lb2=Label(
    info,
    font=('tahoma', 12, 'bold'),
    fg='black',
    text='Version : 1.0\nCopyright © 2018\n',
    justify='center')
      
    lb2.grid()
  
      
################################
# fin patie application : Info #
################################
    
fen = Tk()
fen.geometry('560x300+400+200')
fen.title('System d\'atterissage : ILS')
  
###############################################
# cration de l'icone de la fenetre principale #
###############################################
  
fen.iconbitmap('cev.ico')#code pour visualiser un icone pour l'application
  
##############################
# cration de l'image de fond #
##############################
  
logo=PhotoImage(file='cev.png')
lb_image=Label(fen,image=logo)#code pour visualiser l'image de fond
lb_image.grid()
  
######################################################
# creations des frames : ILS_35L , ILS_35R , ILS_17R #
######################################################
 
 
gp_35L=Frame(fen,width='560',height='300',bg='red')
gp_35L.grid()
gp_35R=Frame(fen, width='560',height='300',bg='pink')
gp_35R.grid()
gp_17R=Frame(fen, width='560',height='300',bg='powder blue')
gp_17R.grid()
loc_35L=Frame(fen, width='560',height='300', bg='green')
loc_35L.grid()
loc_35R=Frame(fen,width='560',height='300',bg='blue')
loc_35R.grid() 
loc_17R=Frame(fen, width='560',height='300',bg='grey')
loc_17R.grid()
 
  
##########################################
# debut du container Menu
##########################################
  
menu=Menu(fen)
 
################
# onglet : ILS#
################
     
 
sousmenu=Menu(menu, tearoff=0)
menu.add_cascade(label='ILS', menu=sousmenu)
 
sous_sousmenu=Menu(sousmenu, tearoff=0)
sousmenu.add_cascade(label='ILS 35R', menu=sous_sousmenu)
 
sous_sousmenu.add_command(label="LOC 35R", command=afficher_loc_35R)
sous_sousmenu.add_command(label="GP 35R", command=afficher_gp_35R)
 
sous_sousmenu=Menu(sousmenu, tearoff=0)
sousmenu.add_cascade(label='ILS 35L', menu=sous_sousmenu)
 
sous_sousmenu.add_command(label="LOC 35L", command=afficher_loc_35L)
sous_sousmenu.add_command(label="GP 35L", command=afficher_gp_35L)
 
sous_sousmenu=Menu(sousmenu, tearoff=0)
sousmenu.add_cascade(label='ILS 17R', menu=sous_sousmenu)
 
sous_sousmenu.add_command(label="LOC 17R", command=afficher_loc_17R)
sous_sousmenu.add_command(label="GP 17R", command= afficher_gp_17R)
 
sousmenu.add_separator()
  
sousmenu.add_command(label="Quitter", command=quitter)
 
fen.config(menu=menu)
   
fen.mainloop()
here is the second code of the reduced application that does not work as I wish: (the application crashes on a color and does not change after several attempts)

#coding:utf-8
  
from tkinter import *
  
############################################
# fonction pour faire basculer l'affichage #
# des frames : ILS_35L , ILS_35R , ILS_17R #
############################################
def faire_apparaitre(frame):
    global fen
    for item in ['loc_35L','loc_17R','loc_35R','gp_17R','gp_35L','gp_35R']:         
        if item==frame:
            supprimer_lb_image ()
            frame.grid()
            
        else:
            frame.grid_forget()
        fen.update()
     
###################################################
# fonction pour faire disparaitre l'image de fond #
###################################################
 
def supprimer_lb_image ():
    global lb_image
         
    if lb_image!=None:
        lb_image.destroy()
        lb_image=None
    else:
        pass
#######################################
#             IMPORTANT (affichage des pages [loc,gp])
##########################################
 
# afficher le contenu de la page (loc_35L)
def afficher_loc_35L():
    supprimer_lb_image ()#je supprime l'image pour afficher les frames
    faire_apparaitre(loc_35L)
 
# afficher le contenu de la page (loc_35R) 
def afficher_loc_35R():
    supprimer_lb_image ()
    faire_apparaitre(loc_35R)
 
     
# afficher le contenu de la page (loc_17R)   
def afficher_loc_17R():
    supprimer_lb_image () #je supprime l'image pour afficher les frames
    faire_apparaitre(loc_17R)
 
 
# afficher le contenu de la page (gp_35L)
def afficher_gp_35L():
    supprimer_lb_image ()#je supprime l'image pour afficher les frames
    faire_apparaitre(gp_35L)
    
# afficher le contenu de la page (gp_35R)
def afficher_gp_35R():
    supprimer_lb_image ()
    faire_apparaitre(gp_35R)
        
# afficher le contenu de la page (gp_17R)  
def afficher_gp_17R():
    supprimer_lb_image () #je supprime l'image pour afficher les frames
    faire_apparaitre(gp_17R)
        
     
def donothing():
   filewin = Toplevel(fen)
   button = Button(filewin, text="Do nothing button")
   button.grid()
     
def quitter():
    fen.destroy()
     
####################################
# A propos de l'application : Info #
####################################
     
def info_de_application():
    info=Toplevel(fen)
    info.title('A propos de l\'application')
    lb1=Label(
    info,
    font=('tahoma', 13, 'bold'),
    fg='black', padx=15,
    text='\nCette application a été conçue pour effectuer\nla correction demandée par l\'avion LABO\ndurant le contrôle en vol, de la ddm du signal\nrayonné par rapport à la ddm exigée par \nl\'avion LABO.\n',
    justify='left')
    lb1.grid()
    lb2=Label(
    info,
    font=('tahoma', 12, 'bold'),
    fg='black',
    text='Version : 1.0\nCopyright © 2018\n',
    justify='center')
      
    lb2.grid()
  
      
################################
# fin patie application : Info #
################################
    
fen = Tk()
fen.geometry('560x300+400+200')
fen.title('System d\'atterissage : ILS')
  
###############################################
# cration de l'icone de la fenetre principale #
###############################################
  
fen.iconbitmap('cev.ico')#code pour visualiser un icone pour l'application
  
##############################
# cration de l'image de fond #
##############################
  
logo=PhotoImage(file='cev.png')
lb_image=Label(fen,image=logo)#code pour visualiser l'image de fond
lb_image.grid()
  
######################################################
# creations des frames : ILS_35L , ILS_35R , ILS_17R #
######################################################
 
 
gp_35L=Frame(fen,width='560',height='300',bg='red')
gp_35L.grid()
gp_35R=Frame(fen, width='560',height='300',bg='pink')
gp_35R.grid()
gp_17R=Frame(fen, width='560',height='300',bg='powder blue')
gp_17R.grid()
loc_35L=Frame(fen, width='560',height='300', bg='green')
loc_35L.grid()
loc_35R=Frame(fen,width='560',height='300',bg='blue')
loc_35R.grid() 
loc_17R=Frame(fen, width='560',height='300',bg='grey')
loc_17R.grid()
 
  
##########################################
# debut du container Menu
##########################################
  
menu=Menu(fen)
 
################
# onglet : ILS#
################
     
 
sousmenu=Menu(menu, tearoff=0)
menu.add_cascade(label='ILS', menu=sousmenu)
 
sous_sousmenu=Menu(sousmenu, tearoff=0)
sousmenu.add_cascade(label='ILS 35R', menu=sous_sousmenu)
 
sous_sousmenu.add_command(label="LOC 35R", command=afficher_loc_35R)
sous_sousmenu.add_command(label="GP 35R", command=afficher_gp_35R)
 
sous_sousmenu=Menu(sousmenu, tearoff=0)
sousmenu.add_cascade(label='ILS 35L', menu=sous_sousmenu)
 
sous_sousmenu.add_command(label="LOC 35L", command=afficher_loc_35L)
sous_sousmenu.add_command(label="GP 35L", command=afficher_gp_35L)
 
 
sous_sousmenu=Menu(sousmenu, tearoff=0)
sousmenu.add_cascade(label='ILS 17R', menu=sous_sousmenu)
 
sous_sousmenu.add_command(label="LOC 17R", command=afficher_loc_17R)
sous_sousmenu.add_command(label="GP 17R", command= afficher_gp_17R)
 
sousmenu.add_separator()
  
sousmenu.add_command(label="Quitter", command=quitter)
  
fen.config(menu=menu)
  
fen.mainloop()
thanks for help
Quote:not work as I wish: (the application crashes on a color and does not change after several attempts)
please elaborate