Apr-18-2020, 06:45 PM
The code works perfectly. when "print(txt_filepath.get)" is executed, the value is "". You have not yet selected a file or set the variable. I rewrote file_dialot() to display the path before drawing the dialog.
Your problem is not a variable issue, but a timing issue. You are trying to use the variable at the wrong time.
def file_dialog(): print('dialog', info_display.get()) getfile = filedialog.askopenfilename(initialdir="/", title="Select log file", \ filetypes=(("log files", "*.log"), ("all files", "*.*"))) filepath = '' + getfile info_display.set(filepath)The first time I select a log file the display is:
Output:dialog
The second time:dialog C:/Python_Musings/test.logThis is the correct output. The first time through the variable has not been set, so the value is "". The second time we see the previously set value is still there.
Your problem is not a variable issue, but a timing issue. You are trying to use the variable at the wrong time.