2017-10-07 2 views
0

J'ai créé une classe qui a une fonction appelée mainScreen(). Il imprime simplement l'écran principal avec deux boutons dessus. Si vous appuyez sur un bouton, il doit aller à une autre fonction appelée inscription(). Je veux effacer tout le cadre et créer de nouveaux widgets, mais je ne peux pas effacer les widgetsremplacement d'une nouvelle interface par une ancienne dans tkinter

class graphics: 
    def __init__(self, master): 
    self.root = master 


    def mainscreen(self): 
     helv36 = tkFont.Font(family='Century Gothic', size=20) 
     mainFrame = Frame(self.root) 
     mainFrame.config(relief='sunken', width=1280, height=720, bg='light 
blue') 
     mainFrame.pack(expand='yes', fill='both') 
     inButton = Button(mainFrame, text = "Sign up", bd = 10, relief = 
GROOVE, font = helv36) 
     inButton.bind("<Button-1>", self.signup) 
     inButton.place(bordermode = OUTSIDE, width =160, height = 60, x = 
600, y = 300) 
     upButton = Button(mainFrame, text = "Sign in", bd = 10, relief = 
GROOVE, font = helv36) 
     upButton.bind("<Button-1>", self.signup) 
     upButton.place(bordermode = OUTSIDE, width =160, height = 60, x = 
600, y = 400) 
     mainFrame.pack_propagate(FALSE) 
     self.root.mainloop() 

    def signup(self,event): 
     signUpShow = Frame(self.root) 
     signUpShow.config(relief='sunken', width=1280, height=720, bg='light 
yellow') 
     signUpShow.pack(expand='yes', fill='both') 
+0

Qu'est-ce qui vous empêche de faire ça? –

+0

Comme dans la fonction de liaison, la mise en attente est transmise à une autre fonction singup() et je ne peux pas accéder à la variable mainFrame à partir de signup() car elle est locale à mainScreen() –

Répondre

0

Vous __init__ doit avoir son code indenté et il a besoin d'un appel à mainscreen. La solution à mainFrame étant locale au sein de mainscreen est de faire aussi un attribut.

self.mainframe = mainFrame = Frame(self.root) 

Ensuite, vous pouvez accéder à self.mainframe au sein signup. Pourquoi ne pouvez-vous pas effacer les widgets?