Menu

PAGE support DEF to display\update Entry widget

2022-03-06
2022-03-07
  • mike pacheco

    mike pacheco - 2022-03-06

    Using Page 7.3 on Win10
    Python 3.10

    Kind of stuck on getting the proper method for displaying the contents of a variable in a PAGE generated UI Window. Did a simple min code example, 1 button and one Entry widget

    Button calls the following from _support

    def importpath_cmd(*args):
    global importentry_path
    import tkinter
    from tkinter import filedialog
    tkinter.Tk().withdraw() # prevents an empty tkinter window from appearing
    importentry_path = filedialog.askopenfilename(title="Select File")
    print(importentry_path)
    _w1.importentry.config(textvariable=importentry_path)
    _w1.importentry.pack()

    I can see the variable correctly in console via print statement , but not in the UI Entry widget.

    Any pointers appreciated.

    M

     
  • mike pacheco

    mike pacheco - 2022-03-06
    def importpath_cmd(*args):
        global importentry_path
        import tkinter
        from tkinter import filedialog
        tkinter.Tk().withdraw()  # prevents an empty tkinter window from appearing
        importentry_path = filedialog.askopenfilename(title="Select File")
        print(importentry_path)
        _w1.importentry.config(textvariable=importentry_path)
        _w1.importentry.pack()
    
     

    Last edit: mike pacheco 2022-03-06
  • Greg Walters

    Greg Walters - 2022-03-06

    Hi Mike,

    It looks like you are trying to get the information back from the askopenfilename function.

    First, your two import statements should be outside the button callback.
    Secondly, you said you have a entry widget on your form, so I'm going to assume you want that to hold the filename returned from the user.

    Your callback function can look something like this...

    def importpath_cmd(*args):
        print('MikePSolution1_support.importpath_cmd')
        for arg in args:
            print('another arg:', arg)
        sys.stdout.flush()
        filename = askopenfilename(title="Select File")
        print(filename)
        _w1.EntryData.set(filename)
    

    In this simple example, filename is the value that is returned from askopenfilename. It gets printed to the terminal and in the last line of the callback it is sent to the Entry widget to be displayed.

    Notice that I set the textvar of the Entry widget to be EntryData. I use the .set() method to put data into the entry widget and if I needed to, I would use the .get() method to get it out.

    I've attached a quick mockup of what I think you are trying to do. If I've missed the mark, please let me know.

    I hope this helps.

    Greg

     
  • mike pacheco

    mike pacheco - 2022-03-07

    Greg,

    Much appreciated, I can see now that I am confusing callback to widgets with variable names , got the change my variable names to make them easier to distinguish as I'm writing the functions.

    Thank you for the great example , just starting down the road with Tkinter ... greatly appreciated!

    M

     
  • Greg Walters

    Greg Walters - 2022-03-07

    I'm glad I was able to help.

    There is a tutorial that I wrote for Don in the Documents folder of your PAGE distribution. You have the basics now, so keep playing. That's the best way to learn.

    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.