Skip to content

Instantly share code, notes, and snippets.

@sampottinger
Created July 9, 2013 03:05
Show Gist options
  • Save sampottinger/5954366 to your computer and use it in GitHub Desktop.
Save sampottinger/5954366 to your computer and use it in GitHub Desktop.
Browse button for entry box: Tkinter
def __browse_for_entry(self, entry_box, dialog_type):
"""Browse for a file and put that filename in an entry box.
@param entry_box: The entry box to put the filename in.
@type entry_box: tkinter.Entry
@param dialog_type: The type of dialog to display. Should be 'open' or
'save as'
@type dialog_type: str
"""
dialog_type = dialog_type.lower()
if dialog_type == 'open':
name = tkfiledialog.askopenfilename(
filetypes=[('CSV files', '.csv')]
)
elif dialog_type == 'saveas':
name = tkfiledialog.asksaveasfilename(
filetypes=[('CSV files', '.csv')]
)
else:
raise ValueError('%s not a valid dialog type.' % dialog_type)
entry_box.delete(0, tkinter.END)
entry_box.insert(0, str(name))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment