For this error, the most common cause is that you are not running the X server.
So you have to type "startx" first then retry with your application.
It also happened to me when I did a "su - anotheruser" and tried to run from anotheruser without having proper access to my $DISPLAY. I quickly solved this by copying .Xauthority from the user running the X server to the users who su to, then did a export DISPLAY=:0
However I am not sure if this is the most secure and apropriate way to do it, but it worked and no longer gtk-warning **: cannot open display: