opening new window in one window using Tkinter -- Help please

Discussion in 'Python' started by Clara, Apr 24, 2005.

  1. Clara

    Clara Guest

    Hi,...
    I meant to write an application where there is a button in a window and
    when you click on the button, it will open a new window, but I want the
    first window to close, replaced by the second window.
    I open a login window and start the mainloop, when the user click on
    the login button, the __call__ function of VerifyProcessor is executed
    and it will call the new window which is the file manager window
    The thing is,.. I don't know how to exit the first mainloop and then
    display the second window...I even tried calling the mainloop again but
    a weird thing happens. I really need help because otherwise I'm stuck
    here and I can't complete my assignment. The following is my code:

    from login import LoginMenu
    app = LoginMenu()
    app.master.title("Login Menu")
    app.master.maxsize(300,200)
    app.mainloop()
    ======================================
    class LoginMenu(Frame):

    def createWidgets(self):
    self.loginButton = Button(self, text='Login', command =
    VerifyProcessor(self.x, self.y, self.msg, self.messageLabel) )

    def __init__(self, master=None):
    Frame.__init__(self, master)
    self.grid(column=6, row=4)
    self.createWidgets()

    class VerifyProcessor:

    def __init__(self, thename, thepass, msg, msglabel):
    self.username = thename
    self.password = thepass
    self.msgVar = msg
    self.msgLabel = msglabel

    def __call__(self):
    import md5
    import dictionaryloader
    found = 0
    theDict = dictionaryloader.loadFrom("Dicttxt")
    entries = theDict.items()
    for theuser, thepass in entries:
    if self.username.get() == theuser and
    md5.new(self.password.get()).hexdigest() == thepass:
    found=1
    from mainmenu import FileManager
    app2 = FileManager(self.username.get())
    app2.master.title("File Manager")
    app2.master.maxsize("400,1500")
    app2.mainloop()
    =====================================================================
    class FileManager(Frame):

    def createWidgets(self, username):
    ...
    def __init__(self, username, master=None):
    Frame.__init__(self, master)
    self.grid(column=6, row=6)
    self.createWidgets(username)
    ======================================================================
     
    Clara, Apr 24, 2005
    #1
    1. Advertising

  2. "Clara" wrote:

    > I meant to write an application where there is a button in a window and
    > when you click on the button, it will open a new window, but I want the
    > first window to close, replaced by the second window.
    > I open a login window and start the mainloop, when the user click on
    > the login button, the __call__ function of VerifyProcessor is executed
    > and it will call the new window which is the file manager window
    > The thing is,.. I don't know how to exit the first mainloop and then
    > display the second window...I even tried calling the mainloop again but
    > a weird thing happens. I really need help because otherwise I'm stuck
    > here and I can't complete my assignment. The following is my code:


    you don't really have to start a new mainloop to create a new toplevel
    window. just call "withdraw" on first window, and create the second
    (as a Toplevel), and Tkinter will take care of the rest.

    </F>
     
    Fredrik Lundh, Apr 24, 2005
    #2
    1. Advertising

  3. Clara

    Clara Guest

    Well, but where do I call withdraw?
     
    Clara, Apr 24, 2005
    #3
  4. Clara

    Clara Guest

    Forgive my ignorance, but where do I call withdraw?
     
    Clara, Apr 24, 2005
    #4
  5. "Clara" wrote:

    > Well, but where do I call withdraw?


    when you want the new window to appear, and the old one to
    go away, of course. something like this, perhaps?

    from mainmenu import FileManager
    app2 = FileManager(self.username.get())
    app2.master.title("File Manager")
    app2.master.maxsize("400,1500")
    - app2.mainloop()
    + app.master.withdraw()

    </F>
     
    Fredrik Lundh, Apr 24, 2005
    #5
  6. Clara

    Clara Guest

    since the file where i call the first window and the second window is
    different,.If I put app.master.withdraw() there,...won't I get error
    message that says; app is not defined as global or something like that?
     
    Clara, Apr 24, 2005
    #6
  7. Clara

    Clara Guest

    I've found the solution!!!!!!!! I must destroy the first window using
    self.master.destroy(), but thanks anyway ^_^
     
    Clara, Apr 25, 2005
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page