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.
defimportpath_cmd(*args):globalimportentry_pathimporttkinterfromtkinterimportfiledialogtkinter.Tk().withdraw()# prevents an empty tkinter window from appearingimportentry_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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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...
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.
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
Last edit: mike pacheco 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...
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
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
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