I’ve been intermittently struggling and totally forgetting about the best way to create cross-platform GUI applications. I’ve veered between Tk for Ruby or Python, JavaFX and Qt.
I recently stumbled on GTK3 in Ruby, and I’ve been going through a couple of tutorials in an attempt to figure it out.
Since I’m back on Debian Stable for 90 percent of my computing, I figured I’d give GTK3 a try. I knew that you could run GTK apps in Windows (and presumably also on MacOS), but maybe I’d have to resort to exotic packaging to make it happen.
(Aside begins here. Feel free to skip it.)
My 2017 HP Envy laptop has spaces on the motherboard for a traditional SATA hard drive and an M.2 NVMe SSD. I am running Debian on a smallish (250 GB) M.2 NVMe and have so far kept Windows 10 on the 1 TB magnetic hard drive. Running each OS on completely separate physical disks is as close as I will get to dual-booting, and my newer (2017) HP laptop handles it better in the BIOS than my older (2012) HP Pavilion laptop. I can even put Linux first in the boot order and have it be the default OS.
So today I booted into Windows. As an aside, it takes at least a half-hour — if not a full hour — for my Windows 10 system on a magnetic hard drive to “stabilize” enough to be actually useful. That’s with Dropbox taking forever both to update itself and then “check for changes” and resolve them.
Believe me when I say that getting an M.2 NVMe SSD is a life-changing upgrade for any computer with any OS. I haven’t tried Windows on an M.2, but Debian 10 with GNOME 3 on an SSD is light years ahead of Windows on a magnetic drive.
It’s not apples-to-apples, but my laptop battery is so old, I can’t really suspend for more than 3⁄4 of a day, and the only way to “survive” with Windows 10 is to suspend/resume instead of cold booting every day. With Debian on the SSD, I can shut down the laptop in fewer than 10 seconds, and boot the next day in less than 30 seconds. And with Debian and even GNOME, the system is ready to use right from the start. With Debian 10 and GNOME 3, this new laptop has none of the problems I have with slowness and overly zealous processes that I have with my 2012 HP laptop and Fedora 30 with GNOME 3. The new laptop is ready to use right after the sub-30-second boot.
(Aside ends. Back to GTK3.)
I didn’t realize how easy it is to run a GTK3 Ruby app in Windows. The key is the MSYS2 system, which brings Linux-ness to Windows. I can’t remember the first time I installed MSYS2 in Windows. Did it come with the Ruby installer? It definitely could have. It could also have come with Git for Windows.
In any event, I have Ruby and MSYS2.
I had just booted into Windows, and at this point I didn’t know MSYS2’s role in all of this. I added the gtk3 Ruby gem at the Windows command line:
$ gem install gtk3
I was then in for a half-hour wait as MSYS2 proceeded to install a lot of things, build many of them from source, and generally get my Windows system ready for GTK3 in Ruby.
After it was all over, I ran one of the Ruby GTK3 tutorial scripts I had been working on in Debian, and it worked. Everything worked the same way.
So GTK3 in Ruby is a legitimate choice for cross-platform development — for Linux and Windows, anyway. What happens in MacOS, I don’t know. I do have a Mac system at my disposal, and I will check the gtk3 Ruby gem on it at some point.
When developing in GTK3, there’s even a graphical Linux program called Glade to help you make GTK GUIs. Plus, did I mention that GTK3 is a current framework that people are using today, and not something for which both development and interest waned in the mid-2000s.
All in all, it seems like a MUCH saner choice than Tk. For the kind of simple applications I’m interested in making, using any compatible language along with GTK3 is very much worth exploring.
Before I close out this post, let me summarize my limited experience with Tk and JavaFX (and you can totally skip this part):
Tk is the “default” GUI toolkit for Ruby, and I think also for Python. It’s easy to get a trivial GUI going with Tk, but the output can be fuzzy looking (in the literal sense) depending on your platform. The method for creating Tk GUIs is much better documented in pre-2000 books focusing on the TCL language — and I’m pretty sure Tk and TCL are really just two sides of the same project.
Plus NOBODY is using Tk, so there is a huge dearth of tutorials and documentation, especially in regard to Tk and Ruby.
Things are much better for Tk and Python. But then again, documentation and enthusiasm are better with EVERY GUI toolkit when it comes to Python. I fully realize that I should just move over to Python. (It could happen.)
I found it too hard to figure out Tk, especially for Ruby.
This is another case of Oracle not caring about Java. In the Java 8 days, which is still now for some platforms, JavaFX, the “latest” Java GUI framework (it’s old, but there’s nothing newer), was included in the JDK and fully integrated in IDEs like Netbeans.
Now that Oracle has cast off JavaFX, and the community is maintaining it, you have to install it separately, and none of the IDEs (Netbeans, IntelliJ, Eclipse) seem to offer an easy path to getting Java 9/10/11/12 working with JavaFX/OpenJFX. If I need a seven-part tutorial just on how to START coding in an IDE, what are the chances that I can actually make a real, working app?
However, during my time using Netbeans 8 and Java 8 with JavaFX built in, I was impressed by some of the things you can do with the GUI. For instance, you can pop in a very nice, well-featured editor.
Note: Developers for Apache Netbeans (it’s no longer an Oracle project) say that with Netbeans 11.1 and 11.2 Beta 2, JavaFX/OpenJFX integration is supposed be easier and better. I’ll wait for the 11.2 release and see how it goes.
Even though JavaFX is quite a bit newer than Tk, it still has relatively few people using it, and there isn’t much when it comes to tutorials or books. It works, but it seems to be strenuously languishing. That said, I might come back to JavaFX. The ability to use one of the big Java IDEs to develop GUI apps without a whole lot of configuration magic would be a big motivator.
tl;dr: Ruby scripts using the gtk3 gem will run on properly configured Linux and Windows computers, making for a true cross-platform solution to developing GUI programs using Ruby (or Python, Perl, C, C++, etc.). It could very well work for what I’m doing better than Tk or JavaFX.
Discuss this post on Reddit and Hacker News.