# How do you open a "Choose File" prompt from Julia?

**URL:** <https://discourse.julialang.org/t/how-do-you-open-a-choose-file-prompt-from-julia/41748>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [June 19, 2020, 8:06pm UTC](https://discourse.julialang.org/t/how-do-you-open-a-choose-file-prompt-from-julia/41748 "2020-06-19T20:06:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![laut](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laut/32/15651_2.png) [@laut](https://discourse.julialang.org/u/laut)\
**Post date:** [June 19, 2020, 8:06pm UTC](https://discourse.julialang.org/t/how-do-you-open-a-choose-file-prompt-from-julia/41748/1 "2020-06-19T20:06:47Z")

</div>

I use `file.choose()` in R to open a “Choose File” window prompt to print a file path for files that I want to reference in my scripts.

Is there a Julia equivalent for this?

---

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [June 19, 2020, 8:10pm UTC](https://discourse.julialang.org/t/how-do-you-open-a-choose-file-prompt-from-julia/41748/2 "2020-06-19T20:10:31Z")

</div>

One option is [Dialogs · Gtk.jl](https://juliagraphics.github.io/Gtk.jl/latest/manual/filedialogs/)

---

<div class="post-metadata">

**Author:** ![Iulian.Cioarca](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iulian.cioarca/32/30166_2.png) [@Iulian.Cioarca](https://discourse.julialang.org/u/Iulian.Cioarca)\
**Post date:** [June 19, 2020, 9:54pm UTC](https://discourse.julialang.org/t/how-do-you-open-a-choose-file-prompt-from-julia/41748/3 "2020-06-19T21:54:00Z")

</div>

`Gtk.jl` is the easiest option. If you like tinkering you can roll your own browser with [CImGui.jl](https://github.com/Gnimuc/CImGui.jl), by using Julia’s `readdir` and `walkdir` and populating CImGui windows with their contents (it will be snappier on Windows).  
Here’s an example of listing the contents of a dir and printing the currently selected item in a window (the code might seem long, but the magic is done inside the bold widget comments):

```julia
using CImGui
using CImGui.CSyntax
using CImGui.CSyntax.CStatic
using CImGui.GLFWBackend
using CImGui.OpenGLBackend
using CImGui.GLFWBackend.GLFW
using CImGui.OpenGLBackend.ModernGL
using Printf

@static if Sys.isapple()
    # OpenGL 3.2 + GLSL 150
    const glsl_version = 150
    GLFW.WindowHint(GLFW.CONTEXT_VERSION_MAJOR, 3)
    GLFW.WindowHint(GLFW.CONTEXT_VERSION_MINOR, 2)
    GLFW.WindowHint(GLFW.OPENGL_PROFILE, GLFW.OPENGL_CORE_PROFILE) # 3.2+ only
    GLFW.WindowHint(GLFW.OPENGL_FORWARD_COMPAT, GL_TRUE) # required on Mac
else
    # OpenGL 3.0 + GLSL 130
    const glsl_version = 130
    GLFW.WindowHint(GLFW.CONTEXT_VERSION_MAJOR, 3)
    GLFW.WindowHint(GLFW.CONTEXT_VERSION_MINOR, 0)
    # GLFW.WindowHint(GLFW.OPENGL_PROFILE, GLFW.OPENGL_CORE_PROFILE) # 3.2+ only
    # GLFW.WindowHint(GLFW.OPENGL_FORWARD_COMPAT, GL_TRUE) # 3.0+ only
end

# setup GLFW error callback
error_callback(err::GLFW.GLFWError) = @error "GLFW ERROR: code $(err.code) msg: $(err.description)"
GLFW.SetErrorCallback(error_callback)

# create window
window = GLFW.CreateWindow(800, 600, "Dir contents")
@assert window != C_NULL
GLFW.MakeContextCurrent(window)
GLFW.SwapInterval(1) # enable vsync

# setup Dear ImGui context
ctx = CImGui.CreateContext()
CImGui.StyleColorsClassic()
fonts_dir = joinpath(@ __DIR__ , "..", "fonts")
fonts = CImGui.GetIO().Fonts
CImGui.AddFontFromFileTTF(fonts, joinpath(fonts_dir, "Roboto-Medium.ttf"), 16)

# setup Platform/Renderer bindings
ImGui_ImplGlfw_InitForOpenGL(window, true)
ImGui_ImplOpenGL3_Init(glsl_version)

try
    # DEFINE YOUR WIDGETS
    default_path = "C:\\Julia-1.4.0"
    show_list = false
    list=Cstring.(pointer.(readdir(default_path)))
    clear_color = Cfloat[0.45, 0.55, 0.60, 1.00]
    while !GLFW.WindowShouldClose(window)
        GLFW.PollEvents()
        # start the Dear ImGui frame
        ImGui_ImplOpenGL3_NewFrame()
        ImGui_ImplGlfw_NewFrame()
        CImGui.NewFrame()
        # we use a Begin/End pair to created a named window.
        @cstatic begin
            CImGui.Begin("List dir contents")
            if CImGui.MenuItem("Open")
                show_list = true
            end
            CImGui.End()
        end
        # show files list
        if show_list
            @c CImGui.Begin("Dir contents", &show_list)
            @cstatic listbox_item_current=Cint(0) begin
            CImGui.Button("Close Me") && (show_list = false;)
            # list box
            @c CImGui.ListBox("listbox\n(single select)", &listbox_item_current, list, length(list), 5)
            crt_pick = unsafe_string(list[listbox_item_current+1])
            CImGui.Text("You selected $crt_pick")
            CImGui.End()
        end
    end
    # END WIDGETS

    # rendering
    CImGui.Render()
    GLFW.MakeContextCurrent(window)
    display_w, display_h = GLFW.GetFramebufferSize(window)
    glViewport(0, 0, display_w, display_h)
    glClearColor(clear_color...)
    glClear(GL_COLOR_BUFFER_BIT)
    ImGui_ImplOpenGL3_RenderDrawData(CImGui.GetDrawData())

    GLFW.MakeContextCurrent(window)
    GLFW.SwapBuffers(window)
    sleep(0.03) #can this be used as update rate?
end
catch e
    @error "Error in renderloop!" exception=e
    Base.show_backtrace(stderr, catch_backtrace())
finally
    ImGui_ImplOpenGL3_Shutdown()
    ImGui_ImplGlfw_Shutdown()
    CImGui.DestroyContext(ctx)
    GLFW.DestroyWindow(window)
end

```

---

<div class="post-metadata">

**Author:** ![laut](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laut/32/15651_2.png) [@laut](https://discourse.julialang.org/u/laut)\
**Post date:** [June 19, 2020, 9:56pm UTC](https://discourse.julialang.org/t/how-do-you-open-a-choose-file-prompt-from-julia/41748/4 "2020-06-19T21:56:33Z")

</div>

On Windows 10

 ![image](https://global.discourse-cdn.com/julialang/original/3X/8/2/82b26cc2a52d1612406a3a77c2b250011c6faa59.png)

---

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [June 19, 2020, 10:06pm UTC](https://discourse.julialang.org/t/how-do-you-open-a-choose-file-prompt-from-julia/41748/5 "2020-06-19T22:06:33Z")

</div>

You’re trying to pass in the value of a variable called `title`, which evidently you never set. Try this: `open_dialog("My first file dialog")`.

---

<div class="post-metadata">

**Author:** ![laut](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laut/32/15651_2.png) [@laut](https://discourse.julialang.org/u/laut)\
**Post date:** [June 19, 2020, 11:12pm UTC](https://discourse.julialang.org/t/how-do-you-open-a-choose-file-prompt-from-julia/41748/6 "2020-06-19T23:12:53Z")

</div>

Thank you.
