Menu

help using a string variable

Anonymous
2024-10-09
2024-10-12
  • Anonymous

    Anonymous - 2024-10-09

    I have a label set up in page, call it, lblMyLabel and in page it is preset to FREDDY and also has a string variable set up lblMyLabel_Var (and set to freddy)
    Ok, now in the SUPPORT file in a certain routine I want to change the var to sometimes show something else.
    I think like lblMyLabel_Var.set("LUCY")
    However in the routine I get
    NameError: name 'lblMyLabel_Var' is not defined

    So how do I change it to something from in a routine in my supportfile??

     
  • Anonymous

    Anonymous - 2024-10-09

    Ahh.... almost soon after I figured out there is an identifier added I was unaware of.
    _name = projectname.TopLevel1(_other name)

    so you need _name.lblMyLabe.... to do the job ...adding this"prefix""did the trick ...Actually I had already tried it, but had forgotten the underscore

     
  • Greg Walters

    Greg Walters - 2024-10-09

    Assuming your Toplevel is named , the main function in the support module will look something like this...

    def main(*args):
        '''Main entry point for the application.'''
        global root
        root = tk.Tk()
        root.protocol( 'WM_DELETE_WINDOW' , root.destroy)
        # Creates a toplevel widget.
        global _top1, _w1
        _top1 = root
        _w1 = labeldemo.Toplevel1(_top1)
        root.mainloop()
    

    Notice there is a _top1 alias that is set to root and a _w1 alias that points to that as well.

    To set the label in code you can do it one of two ways...
    Number 1:

    prepend the label textvariable like _w1.lblMyLable_Var.set('Frogbreath')

    Number 2:
    You can also directly use the config method...

    _w1.lblMyLaabel.config(text='Frogbreath")

    Either of these should work.

     
  • Anonymous

    Anonymous - 2024-10-12

    yes, my main issue was not including w1 , just the name of the label...it was initially confusing to me that it said it didn't know what that was

    this looks like some crazy sort of shell game
    global root
    root = tk.Tk()
    root.protocol( 'WM_DELETE_WINDOW' , root.destroy)
    # Creates a toplevel widget.
    global _top1, _w1
    _top1 = root
    _w1 = labeldemo.Toplevel1(_top1)

    root?  Toplevel1?  top1?  _w1?  ...why so many?
    
     

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.