Menu

Multiple Windows

Anonymous
2020-12-08
2020-12-09
  • Anonymous

    Anonymous - 2020-12-08

    I'm have the main window and secondary one. I'm trying to call the second one and change it's label, but i'm not getting

    main_support.py

       import restrito
       import restrito_support
    
       restrito.vp_start_gui()
       restrito_support.setLabelText() 
    

    restrito_support.py

    def setLabelText():
        w.msg_recebida.configure(text='Hi there')
    

    Error: NameError: name 'w' is not defined

    I'm doing like documentation says as example: w.Button1.configure(color='red')

     
  • Greg Walters

    Greg Walters - 2020-12-08

    Since you did not provide your source project, I threw together this demo for you.
    Hopefully, it works for you as it does for me.

    Greg

     
  • Anonymous

    Anonymous - 2020-12-08

    I see your code and notice that I hadn't called the toplevel. So I change in main_support.py (restrito and restrito_support are files of secondary window):

    import restrito
    import restrito_support
     restrito.vp_start_gui()
     restrito_support.setLabelText(username)
    

    to:

           import restrito
           import restrito_support
           restrito.create_Toplevel1(root)
           restrito_support.setLabelText(username)
    

    And works now. But, can you please explain why I need to call Toplevel1 to avoid "w is not defined"? Just starting with PAGE and I'm really enjoying it

    Thanks

     
  • Greg Walters

    Greg Walters - 2020-12-09

    The reason is pretty simple, actually. If you take a look at the function that is in the child.py file (or in your case the restrito.py file) you will see the following...

    def create_Toplevel1(rt, *args, kwargs):
    '''Starting point when module is imported by another module.
    Correct form of call: 'create_Toplevel1(root, *args,
    kwargs)' .'''

    Notice the comment. "Starting point when the module is imported by another module".

    Now look at the function above it in the same python file...

    def vp_start_gui():
    '''Starting point when module is the main routine.'''

    Again, the comment says it all. When the module is the main routine.

    When you are instantiating a new form, you have to use the create_Toplevel1 function. The name of this can change, if you set the alias for the toplevel widget (the design form that you put all the widgets on) to something else. So assuming that you alias the toplevel form to "MyPrettyForm", the function would be called "create_MyPrettyForm()".

    I hope this helps.

    Greg

     

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.