If you are facing this error (main:30677): Gtk-WARNING **: 05:40:47.665: cannot open display: just install Gtk+ development library, and set the display screen to 0.

Installing Gtk+ using Homebrew

If you are using a UNIX-like OS such as Mac OS X, or a Linux distribution. You can use Homebrew package manager to install Gtk+ as following.

brew install Gtk+

Install Gtk+ using apt

If you are using Debian, Ubuntu, Elementary OS, Linux Mint, .. You can use this command to install Gtk+.

sudo apt-get install libgtk-3-dev

Set DISPLAY Environment Variable

If the error persists, just run this command on terminal to set the display to the current display/monitor/screen.

export DISPLAY=":0"

If the display command fixed the error, add those lines into your .bashrc or .zshrc (according to what you are using).

if [[ -z "$DISPLAY" ]]
    export DISPLAY

Use X11 XQuartz on Mac

If your application still showing the same error on Mac OS, just install XQuartz from here https://www.xquartz.org and restart. Your Gtk apps will work after that.

I hope this helps. Do you recommend reading this blog post? share it!