Search code examples
pythonuser-interfacetkinterframefiledialog

How to create a FileDialog to appear in a frame of a window instead of the FileDialog being a popout window?


How can I embed a FileDialog that appears in the frame on the left when the application opens instead of clicking a button "browse" and having the FileDialog be a popout window?

I have created a GUI using Python and in the window I have a frame on the left and a Listbox on the right.

def browseButtonClicked():

    browsePath = filedialog.askopenfilename()
            .
            .
            .


# GUI setup
root = Tk()

mainframe = ttk.Frame(root)
browseFrame = ttk.Frame(mainframe)

sfPathLB = Listbox(browseFrame, height=12, width=40, selectmode=MULTIPLE)

browseButton = ttk.Button(mainframe, text="Browse", 
command=browseButtonClicked)

browseFrame.grid(column=1, row=2, rowspan=3, padx=3, sticky=(W+E+N+S))

sfPathLB.grid(column=3, row=2, rowspan=3, padx= 3, sticky=(W+E+N+S))

When I did add the filedialog inside the frame:

frame.browseFrame = filedialog.askopenfilename()

The filedialog opened when I executed the program, but it took over the entire window instead of just appearing in the frame.


Solution

  • How to create a FileDialog to appear in a frame of a window instead of the FileDialog being a popout window?

    You can't. The dialogs are controlled by the OS. You can't embed them.