0

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.

martineau
  • 119,623
  • 25
  • 170
  • 301
omgsyd28
  • 27
  • 3
  • 1
    A *dialog* implies a widget type opened in its own window. – ipaleka Jul 01 '19 at 15:55
  • Is there something else out there that give me the same result? Or can you recommend an alternative option? @ipaleka – omgsyd28 Jul 01 '19 at 15:58
  • You may try put everything in the frame widget inside that left frame invisible on start and show it upon call. – ipaleka Jul 01 '19 at 16:01
  • Regarding @ipaleka's last comment: There's a `Frame.tkraise()` method that allows changing the rendering order of its contents which would allow hiding it until needed. There's an example of using it in this [answer](https://stackoverflow.com/a/7557028/355230) to another tkinter-related question. – martineau Jul 01 '19 at 17:01

1 Answers1

1

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.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685