Friday, 15 August 2014

How do I get a function that uses Tkinter 8.5 to return the selected file from a file dialog box -



How do I get a function that uses Tkinter 8.5 to return the selected file from a file dialog box -

i filename in vendorfunction() obtain user's input in entry box after user clicks format button. newbie , can't figure out how this. below code:

from tkinter import * tkinter import ttk def createvendorwindow(): def browse(): fileselected = filedialog.askopenfilename() guiinputfileentry.insert(0, fileselected) def format(file): homecoming file vendorwindow = tk() vendorwindow.title("cost load converter") vendorwindowframe = ttk.frame(vendorwindow, padding="12 12 7 7") vendorwindowframe.grid(column=0, row=0, sticky=(n,w,e,s)) vendorwindowframe.columnconfigure(0, weight=1) vendorwindowframe.rowconfigure(0, weight=1) guiinputfile = stringvar() guiinputfileentry = ttk.entry(vendorwindowframe, width=100, textvariable=guiinputfile) guiinputfileentry.grid(column=1, row=1, stick=(w,e)) ttk.label(vendorwindowframe, text="\nplease come in total filepath of file wish format:").grid(column=1, row=0) browsebutton = ttk.button(vendorwindowframe, text="browse...", underline=0, command=browse) browsebutton.grid(column=2, row=1, padx=5) formatbutton = ttk.button(vendorwindowframe, text="format", underline=0, command= lambda: format(guiinputfileentry.get())) formatbutton.grid(column=1, row=2, pady=5) vendorwindow.mainloop() def vendorfunction(): filename = createvendorwindow() print("filename: ", filename) #then, stuff filename vendorfunction()

thanks in advance!

right now, format function returns filename, want createvendorwindow function homecoming filename. should set return guiinputfile.get() behind vendorwindow.mainloop(). format button needs close window: command=lambda: vendorwindow.destroy(). stops mainloop , starts executing behind mainloop.

tkinter

No comments:

Post a Comment