Search code examples
pythonpython-2.7tkinteralignmenttkinter-entry

How to set to see end of text in Tkinter Entry widget?


I am making a gui interface to make my script available to general user. My question is - I have a entry widget which takes 'file path' as value when user picks a file using browse button. Problem is entry widget shows the beginning (left end) of file path but I would prefer to see the right end of the file path.

And here is my script.

from Tkinter import *
from tkFileDialog import askopenfilename

app = Tk()
app.title("ABC")
app.geometry("300x100")

def browse_for_file(entry_name, filetype):
    File_path = askopenfilename(filetypes = filetype)
    entry_name.delete(0, END)
    entry_name.insert(0, File_path)

templ_filename = StringVar()
templ_entry = Entry(app, textvariable = templ_filename, width = 30)
templ_entry.grid(row = 3, column = 1, sticky=W)

filetype_fasta = [('fasta files', '*.fasta'), ('All files', '*.*')]
button_templ = Button(app, text = 'Browse', width =6, command = lambda:browse_for_file(templ_entry, filetype_fasta))
button_templ.grid(row = 3, column = 2)

app.mainloop()

Solution

  • Use

    entry.xview_moveto(1)
    

    xview_moveto() takes fractions, where 0 defines the left and 1 the right part.