# Setting size of GtkCanvas and other widgets

**URL:** <https://discourse.julialang.org/t/setting-size-of-gtkcanvas-and-other-widgets/14658>\
**Category:** New to Julia\
**Created:** [September 7, 2018, 9:26am UTC](https://discourse.julialang.org/t/setting-size-of-gtkcanvas-and-other-widgets/14658 "2018-09-07T09:26:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bill-p](https://avatars.discourse-cdn.com/v4/letter/b/b3f665/32.png) [@bill-p](https://discourse.julialang.org/u/bill-p)\
**Post date:** [September 7, 2018, 9:26am UTC](https://discourse.julialang.org/t/setting-size-of-gtkcanvas-and-other-widgets/14658/1 "2018-09-07T09:26:16Z")

</div>

I’m wanting to make a GUI with several items - I made a GtkBox(:v), and pushed in a GtkBox(:h),  
followed by a GtkCanvas(), then another GtkBox(:h). The hBoxes contain buttons, labels, etc.  
When I call showall(win) it brings up the two hBoxes Ok, but the canvas is sqeezed down to a thin line.  
What I want is for it to fill the space between the hboxes. If I call GtkCanvas(width,height) then that  
gives me a useable canvas, but it prevents me from resizing the window to less than that size.  
I thought if I could trap the resize events I could use set\_gtk\_property() to adjust the size but I can’t  
figure out what string to use with signal\_connect(). That would also be useful to adjust sizes in the  
hBoxes.

---

<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:** [September 7, 2018, 10:27am UTC](https://discourse.julialang.org/t/setting-size-of-gtkcanvas-and-other-widgets/14658/2 "2018-09-07T10:27:14Z")

</div>

have you expanded the canvas?

```julia
set_gtk_property!(mybox,:expand,mycanvas,true)

```

where `mybox` is the box and `mycanvas` is the canvas.

---

<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:** [September 7, 2018, 10:34am UTC](https://discourse.julialang.org/t/setting-size-of-gtkcanvas-and-other-widgets/14658/3 "2018-09-07T10:34:30Z")

</div>

Here is a working example (modified from the docs):

```julia
using Gtk
c = @GtkCanvas()
b = GtkBox(:h)
push!(b,c)
set_gtk_property!(b,:expand,c,true)
win = GtkWindow(b, "Canvas")
@guarded draw(c) do widget
    ctx = getgc(c)
    h = height(c)
    w = width(c)
    # Paint red rectangle
    rectangle(ctx, 0, 0, w, h/2)
    set_source_rgb(ctx, 1, 0, 0)
    fill(ctx)
    # Paint blue rectangle
    rectangle(ctx, 0, 3h/4, w, h/4)
    set_source_rgb(ctx, 0, 0, 1)
    fill(ctx)
end
showall(win)

```

The interesting thing is, that I need `showall(win)` to actually show the canvas. I am not sure why that but stumbled on this several times.

---

<div class="post-metadata">

**Author:** ![bill-p](https://avatars.discourse-cdn.com/v4/letter/b/b3f665/32.png) [@bill-p](https://discourse.julialang.org/u/bill-p)\
**Post date:** [September 7, 2018, 10:40am UTC](https://discourse.julialang.org/t/setting-size-of-gtkcanvas-and-other-widgets/14658/4 "2018-09-07T10:40:09Z")

</div>

Thanks, that certainly sorts out the canvas problem.

---

<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:** [January 3, 2020, 10:46pm UTC](https://discourse.julialang.org/t/setting-size-of-gtkcanvas-and-other-widgets/14658/5 "2020-01-03T22:46:35Z")

</div>

> [@bill-p](#):
>
> n) it brings up the two hBoxes Ok, but the canvas is sqeezed down to a thin line.  
> What I want is for it to fill the space between the hboxes. If I call GtkCanvas(width,height) then that  
> gives me a useable canvas, but it prevents me from resizing the window to less than that size.  
> I thought if I could trap the resize events I could use set\_gtk\_property() to adjust the size but I can’t  
> figure out what string to use with signal\_connect(). That would also be useful to adjust sizes in the  
> hBoxes.

How can I manually set the size (pixel number) for a button? So that it does not scale to the text but relative to some other number
