Python Forum
[Tkinter] Unable to get current contents of the entry field where the content is the file path
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Unable to get current contents of the entry field where the content is the file path
#2
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.
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.log
This 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.
Reply


Messages In This Thread
RE: Unable to get current contents of the entry field where the content is the file path - by deanhystad - Apr-18-2020, 06:45 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] remove file from current project rwahdan 2 2,333 Jul-25-2021, 09:14 AM
Last Post: Larz60+
  [Tkinter] compare entry with value inside file rwahdan 1 2,100 Jun-19-2021, 08:01 AM
Last Post: Yoriz
  Disable entry field and still see value scratchmyhead 5 5,180 May-11-2020, 08:09 PM
Last Post: menator01
  Converting Entry field value to integer in tkinter scratchmyhead 2 5,006 May-11-2020, 03:41 PM
Last Post: scratchmyhead
  Transfer Toplevel window entry to root window entry with TKinter HBH 0 4,496 Jan-23-2020, 09:00 PM
Last Post: HBH
  [Tkinter] Unable to save filepath to config.ini file using filedialog.askopenfilename JackMack118 10 5,066 Dec-29-2019, 08:12 PM
Last Post: JackMack118
  [PyQt] Collect entry from textline Widget via UI file mart79 3 2,938 Aug-05-2019, 01:40 PM
Last Post: Denni
  [Tkinter] How to get the name of a file only from a file path ? DT2000 4 10,452 Jul-25-2019, 08:27 PM
Last Post: DT2000
  [Tkinter] how to get the entry information using Entry.get() ? SamyPyth 2 3,530 Mar-18-2019, 05:36 PM
Last Post: woooee
  [Tkinter] Displaying file's contents as labels gellerb 3 3,323 Apr-02-2018, 01:35 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020