This repository provides examples on using GTK4 and GTK3 using the gotk4 bindings.
GTK4 examples are in ./gtk4. A simple Hello World example is in ./gtk4/simple.
Before running any of these examples, you must grab the dependencies in your operating system or distribution.
Below are instructions for getting the needed dependencies for GTK on certain distros. Most distros and operating systems will be missing from this list, so PRs are welcomed.
nix-shell -p '<nixpkgs>' gtk4 gnome3.gtk gobjectIntrospection pkgconfig
sudo pacman -S gtk4 gobject-introspection
sudo apt install libgtk-3-dev # 18.04 (bionic) or later
sudo apt install libgtk-4-dev # 21.04 (hirsuit) or later
sudo dnf install gtk4-devel gobject-introspection-devel
brew install gtk4 gtk+3 gobject-introspection pkg-config
The minimum Go version required to run gotk4
is 1.17. If your distribution or
operating system does not have 1.17, follow the steps under the "Other
OS/distros" section.
nix-shell # will grab both Go and all GTK dependencies
Snippet taken from the Go wiki:
sudo add-apt-repository ppa:longsleep/golang-backports
sudo apt update
sudo apt install golang-go # or golang-1.17
sudo dnf install golang
The packaged version of Go on Fedora is usually a few versions behind upstream on non-rawhide branches, so you might want to manually install Go using the installation instructions mentioned below.
Follow doc/install for more information.
This snippet assumes that you've already cloned this repository down and are currently inside the repository.
go run -v ./gtk4/simple
Important: if you don't run with -v
, you might start wondering if go run
is hung or not. Always keep in mind that building gotk4
will be very slow at
first, and the slow building is normal.