58
submitted 2 months ago by kristoff@infosec.pub to c/linux@lemmy.ml

Hi all,

Perhaps a stupid question. Some time ago, I received a rpi zeroW as a gift, but as I did not have any use for ii I passed it to somebody else in our electronics-group. Now, that person has had a +30 year carreer as self-taught programmer -starting out with BASIC on DOS machines- so he showed of some of his old BASIC applications in dosbox on the pi.

So far so good, but he had an interesting question: Years ago, I wrote a library in BASIC for screen / window applications in DOS. (you know, pop-up text-windows and so on). How do I do that on linux (in C)?

As I myself only do 'backend' coding (so no UI), I have to admit I did not have any answer to that.

So, question, For somebody who has mostly coded in BASIC (first DOS and later Visual Basic) and now switched to C and python, what is the best / most easy tool to write a basic UI application with window-function on linux/unix. I know there exist things like QT and ncurses, but I never used these, so I have no idea.

Any advice?

Kr.

all 40 comments
sorted by: hot top controversial new old
[-] INeedMana@lemmy.world 19 points 2 months ago

wrote a library in BASIC for screen / window applications in DOS. (you know, pop-up text-windows and so on). How do I do that on linux (in C)?
(...)
I know there exist things like QT and ncurses

So it's graphical interface we are after or text based?

For text, I agree with others, ncurses

For graphical

  • pyGTK
    basically everything you need, some learnig curve as it's big and versatile. But to be honest, when trying to achieve something I'd suggest to start from GTK reference to me it somehow conveys the logic better than the PyGTK reference
  • Kivy
    haven't used it, but might be fun to use
  • wxWidgets
    very cross-platform. Not only you can use it to write UI that will require minor fixes to have the same code for Windows and Linux at the same time, you can also tell it whether the toolkit used under the hood on Linux should be QT or GTK
  • Tk
    old, simple (more fancy things need some gymnastics) but simple (easy to use) and supported in Python out of the box (you don't even need to install anything)
  • QT
    I'm putting it here just for fairness. I don't like it, don't like its signal-slot design, I think it's hogging up too much resources. But last time I used it was ~10 years ago and in the end, it does in fact work
[-] kristoff@infosec.pub 7 points 2 months ago

Wauw! So many answers in such a short time. Thanks all! 👍 (I will not spam the channel by sending a thank you to all but this is really greatly apriciated)

Concerning ncurses. I did hear of it but never looked at it myself. What is not completely clear for me. I know you can use it for 'low-level' things, but does it also include 'high-level' concepts like windows, input fields and so?

The blog mentioned in one of the other posts only shows low-level things.

[-] pnutzh4x0r@lemmy.ndlug.org 4 points 2 months ago

For higher level widgets in ncurses, you can use a library like textual or urwid.

[-] MyNameIsRichard@lemmy.ml 3 points 2 months ago

but does it also include ‘high-level’ concepts like windows, input fields and so

Yes, it allows you build full on TUIs.

[-] INeedMana@lemmy.world 1 points 2 months ago

does it also include ‘high-level’ concepts like windows, input fields and so?

AFAIK MC uses ncurses for GUI. So I while I don't know if it has the concept of non-modal dialog, for example, for sure it has dialogs, fields, radios, boxes, etc

[-] MyNameIsRichard@lemmy.ml 15 points 2 months ago

If you want a terminal gui, then ncurses may be suitable which you can also use in c++. Qt and Gtk have c++ bindings.

[-] DieserTypMatthias@lemmy.ml 7 points 2 months ago

I'd recommend egui, though you have to use Rust for it. (learning it should be easy, considering the fact that you have background in C).

[-] 0x0@programming.dev 7 points 2 months ago
[-] Max_P@lemmy.max-p.me 6 points 2 months ago* (last edited 2 months ago)

Both GTK and Qt have good Python bindings.

GTK example: https://github.com/Taiko2k/GTK4PythonTutorial

There's also PyQt but it looks more complicated and I couldn't find as nice and straightforward of an example as GTK but I found this: https://realpython.com/qt-designer-python/

If you want to go to C, GTK works about the same way. If you want C++, Qt is pretty good there.

Otherwise you can go SDL and just put whatever pixels you want on the screen on your own.

[-] nickb333@fedia.io 4 points 2 months ago

I class myself as having similar experience to your friend having used Power Basic and Turbo Pascal mainly under DOS. I was able to use tkinter to produce some simple gui front-ends to produce dialogue boxes, process data and feed it to GnuPlot.

[-] 737@lemmy.blahaj.zone 4 points 2 months ago

Raygui, fltk, GTK. Qt if you're working in C++

[-] possiblylinux127@lemmy.zip 4 points 2 months ago

You don't

Use existing frameworks like GTK and QT

[-] dev_null@lemmy.ml 3 points 2 months ago

It really depends on which language you want to use.

[-] sirico@feddit.uk 3 points 2 months ago* (last edited 2 months ago)

FOr me the quickest and basic way would be python and tkinter or pyqt. Failing that, push it to a web app with something like Flask or React

[-] Truck_kun@beehaw.org 2 points 2 months ago* (last edited 2 months ago)

You listed python.

If you are open to Python, I would recommend: https://textual.textualize.io/

Edit: for clarity, the above is if you want nice TUIs (text gui in terminal). If you want actual windowed applications not in terminal, in regards to Python, I would just say use tkinter.

Here's a list of projects known to use Textual: https://github.com/Textualize/transcendent-textual

There are a lot of cool projects I would suggest browsing to see what it can do, but the following pages have screenshots that do a good job of showing what it's capable of:

https://github.com/ChrisBuilds/moneyterm

https://github.com/bluematt/textual-musicplayer

https://github.com/eliasdorneles/usolitaire (I'd love to see someone do minesweeper for terminal)

Extra: while meant for terminal usage, you can use the mouse to interact, can run programs from ssh sessions, and I believe they’ve added the ability to take your TUI into web browsers.

…. Oh, also not restricted to Linux. It does generally work with Mac and windows (would recommend using windows terminal from windows store, it makes things look right, whereas command prompt does not display correctly.

[-] FQQD@lemmy.ohaa.xyz 2 points 2 months ago

I'm not that deep into the topic, but I experimented with GTK and tkinter as a kid

[-] damnthefilibuster@lemmy.world 2 points 2 months ago

I’ve used pyTK to make some apps for personal use. Good stuff, somewhat easy to use once you follow some tutorials.

[-] johant@lemmy.ml 2 points 2 months ago

There is also newt which is: ...a programming library for color text mode, widget based user interfaces.

It also comes with the whiptail command for creating TUI interfaces for shell scripts. Similar to dialog (ncurses) or zenity (QT).

[-] fhein@lemmy.world 2 points 2 months ago

Easiest GUI toolkit I've used was NiceGUI. The end result is a web app but the python code you write is extremely simple, and it felt very logical to me.

this post was submitted on 13 Aug 2024
58 points (96.8% liked)

Linux

48074 readers
668 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS