# Tips for high level structuring of a Gtk.jl UI

**URL:** <https://discourse.julialang.org/t/tips-for-high-level-structuring-of-a-gtk-jl-ui/31090>\
**Category:** General Usage\
**Tags:** question\
**Created:** [November 14, 2019, 5:12pm UTC](https://discourse.julialang.org/t/tips-for-high-level-structuring-of-a-gtk-jl-ui/31090 "2019-11-14T17:12:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mantzaris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mantzaris/32/3852_2.png) [@mantzaris](https://discourse.julialang.org/u/mantzaris)\
**Post date:** [November 14, 2019, 5:12pm UTC](https://discourse.julialang.org/t/tips-for-high-level-structuring-of-a-gtk-jl-ui/31090/1 "2019-11-14T17:12:30Z")

</div>

I am using `Gtk.jl` to work on a UI. There will be multiple windows and components with the box layouts in different sections. I am wondering what is the recommended structuring for the definition and organization of the components. I have had the individual components as global variables am now putting them into a dictionary which is set to global as well.

My question is whether there is a recommended or preferred way to do this? Should I set the dictionary in the main function which is passed around for the updating? Should I have the components in a `struct` instead? Should the different windows be in different dictionaries or structs?

---

<div class="post-metadata">

**Author:** ![tobias.knopp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tobias.knopp/32/7551_2.png) [@tobias.knopp](https://discourse.julialang.org/u/tobias.knopp)\
**Post date:** [November 14, 2019, 7:24pm UTC](https://discourse.julialang.org/t/tips-for-high-level-structuring-of-a-gtk-jl-ui/31090/2 "2019-11-14T19:24:35Z")

</div>

There is not really a recommended structure yet and I am playing around with this myself. What I usually do is to put substructures into a common custom widget, which is basically always a grid with various widgets insides. I use this approach:

[Custom/Composed Widgets · Gtk.jl](https://juliagraphics.github.io/Gtk.jl/latest/manual/customWidgets/)

where the new widget haves just like a regular Gtk widget. Each of these custom widgets gets a dedicated Glade UI file and from within the constructor I pull out the widgets and put them into fields of the struct. Another pattern is this

```julia

mutable struct DataViewerWidget <: Gtk.GtkBox
  handle::Ptr{Gtk.GObject}
  builder::Builder
  ...
end

getindex(m::DataViewerWidget, w::AbstractString) = G_.object(m.builder, w)

function DataViewerWidget()
  uifile = joinpath(@ __DIR__ ,"..","builder","dataviewer.ui")

  b = Builder(filename=uifile)
  mainBox = G_.object(b, "boxDataViewer")
  m = DataViewerWidget( mainBox.handle, b, ...)
  
  # Now I can do this:

  m["myWidgetInTheGladeFile"]

  return m
end

```
