# GTK screen updating

**URL:** https://discourse.julialang.org/t/gtk-screen-updating/137322
**Category:** Performance
**Tags:** gtk
**Created:** [May 28, 2026, 4:14pm UTC](https://discourse.julialang.org/t/gtk-screen-updating/137322 "2026-05-28T16:14:18Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![isaac-aderemi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/isaac-aderemi/32/221778_2.png) [@isaac-aderemi](https://discourse.julialang.org/u/isaac-aderemi)
#### Post date: [May 28, 2026, 4:14pm UTC](https://discourse.julialang.org/t/gtk-screen-updating/137322/1 "2026-05-28T16:14:18Z")

</div>

# My question

How does a person update the screen in gtk for a game or video updating?

# notes

Glade was used to make the following code and I was wondering how I would update the screen (the ppm that is currently being used is just a placeholder)  
this is the relevant image class that i wanted to update (about 60 times a second at 1920 by 1080 pixels)

```julia-auto
<object class="GtkImage">
                    <property name="width-request">100</property>
                    <property name="height-request">80</property>
                    <property name="visible">True</property>
                    <property name="can-focus">False</property>
                    <property name="pixbuf">image.PPM</property>

```

how would I update the image?  
This is the code I am using for the placeholder image

```julia-auto
function GHW()
            nx = 1920 - 200
            ny = 1080 - 200
            open("image.PPM", "w") do image  
                        write(image,"P3\n" , string(nx) , " " , string(ny) , "\n" , string(255) , "\n")
                        for i in 1 : ny
                                    for j in 1 : nx
                                                r = (nx - j) / nx
                                                g = i / ny 
                                                b = (i*j) / (nx*ny)
                                                ir = string(Integer(255 - trunc(255.99*r)))
                                                write(image, ir , " ")
                                                ig = string(Integer(255 - trunc(255.99*g)))
                                                write(image,ig , " ")
                                                ib = string(Integer(trunc(255.9*b)))
                                                write(image,ib , " ")
                                                write(image, "\n")
                                    
                                    end
                        end
            end

            nx = round(Int,nx / 3)
            ny = round(Int,ny / 3)
            open("mini_image.PPM", "w") do image  
                        write(image,"P3\n" , string(nx) , " " , string(ny) , "\n" , string(255) , "\n")
            
                        for i in 1 : ny
                                    for j in 1 : nx
                                                r = (nx - j) / nx
                                                g = i / ny 
                                                b = (i*j) / (nx*ny)
                                                ir = string(Integer(255 - trunc(255.99*r)))
                                                write(image, ir , " ")
                                                ig = string(Integer(255 - trunc(255.99*g)))
                                                write(image,ig , " ")
                                                ib = string(Integer(trunc(255.9*b)))
                                                write(image,ib , " ")
                                                write(image, "\n")
                                    
                                    end
                        end
            end
end

```

If possible please help change the size of the image dependent on window size too that would be great

---

<div class="post-metadata">

### Author: ![eldee](https://avatars.discourse-cdn.com/v4/letter/e/b5a626/32.png) [@eldee](https://discourse.julialang.org/u/eldee)
#### Post date: [June 6, 2026, 5:50pm UTC](https://discourse.julialang.org/t/gtk-screen-updating/137322/2 "2026-06-06T17:50:30Z")

</div>

Hi, and welcome to the Julia community!

* * *

> [@isaac-aderemi](#):
>
> Glade was used

Are you using Gtk.jl? If so, this is deprecated and you should switch to Gtk4.jl.

* * *

With the caveat that I’m not an expert, and that this approach is presumably not optimal in any way, the following kind of works:

```julia
using Gtk4
using Images # for RGB{N0f8} (could use a smaller dependency)
using Random # for rand!

width = 1920
height = 1080

win = GtkWindow("Random pixels", width, height)
pic = GtkPicture()
win[] = pic # or push!(win, pic)

img = rand(RGB{N0f8}, width, height)
pixbuf = Gtk4.GdkPixbuf(img)

g_timeout_add(33) do # 33 ms: 30 fps
	rand!(img) # updates img, hence pixbuf
	pic.paintable = Gtk4.GdkTexture(pixbuf)
	return true # never stop
end

```

(You could also create `pic = GtkPicture(pixbuf)`, the image data of which should update when we call `rand!(img)`. But Gtk does not realise anything has changed, and thus does not redraw. Methods like `show`, `reveal`, and a (possibly incorrect)

```julia-auto
ccall((:gtk_widget_queue_draw, Gtk4.libgtk4), Nothing, (Ptr{Gtk4.GObject},), pic)

```

seem unable to force an update. Setting `pic.paintable` to a newly created texture does.)

* * *

The `GtkPicture` automatically scales to fill the window size as much as possible, while preserving the aspect ratio. It seems to use basic linear interpolation. Therefore, you don’t necessarily have to correlate `size(img)` with the window size.
