< GTK

GTK/Development

Write a simple message dialog app

You can write your own GTK 3 message dialog easily in many programming languages through GObject-Introspection or bindings, or you can simply use bash.

The following examples display a simple "Hello world" in a message dialog.

Ada

  • Dependency: gtkadaAUR
  • Makedependency: gcc-ada
  • Build with: gnatmake hello_world `gtkada-config`
hello_world.adb
with Gtk.Main;
with Gtk.Dialog;           use Gtk.Dialog;
with Gtk.Message_Dialog;   use Gtk.Message_Dialog;

procedure hello_world is
  Dialog   : Gtk_Message_Dialog;
  Response : Gtk_Response_Type;
begin
  Gtk.Main.Init;
  Gtk_New (Dialog   => Dialog,
           Parent   => null,
           Flags    => 0,
           The_Type => Message_Info,
           Buttons  => Buttons_OK,
           Message  => "Hello world!");
  Format_Secondary_Markup (Dialog, "This is an example dialog.");
  Response := Run (Dialog);
end hello_world;

Bash

hello_world.sh
#!/bin/bash
zenity --info --title='Hello world!' --text='This is an example dialog.'

BASIC

hello_world.bas
#include "Gir/Gtk-3.0.bi"
Dim As GtkWidget Ptr hello
gtk_init (cast(gint ptr, @__fb_argc__), @__fb_argv__)
hello = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "Hello world!")
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (hello), "This is an example dialog.")
gtk_dialog_run (GTK_DIALOG (hello))

Boo

  • Dependency: (and booAUR)
  • Makedependency: booAUR
  • Build with:
  • Run with: (or )
hello_world.boo
import Gtk from "gtk-sharp"
Application.Init()
Hello = MessageDialog(null, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, "Hello world!")
Hello.SecondaryText = "This is an example dialog."
Hello.Run()

C

  • Dependency: gtk3
  • Build with: gcc -o hello_world $(pkg-config --cflags --libs gtk+-3.0) hello_world.c

C++

  • Dependency:
  • Build with:

C#

  • Dependency:
  • Build with:
  • Run with:

Clojure

  • Dependencies: ,
  • Run with:
project.clj
(defproject hello-world "0.1.0-SNAPSHOT"
  :main hello-world.core
  :dependencies [[org.clojure/clojure "1.10.3"]]
  :resource-paths ["/usr/share/java/gtk.jar"])

Crystal

D

  • Dependency: gtkd
  • Makedependency:
  • Build with:

F#

  • Dependency:
  • Run with:
hello_world.fsx
#r "nuget: GtkSharp"
open Gtk

let main () =
  Application.Init()
  let Hello = new MessageDialog(null, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, "Hello world!")
  Hello.SecondaryText <- "This is an example dialog."
  Hello.Run() |> ignore

main ()

Fortran

  • Dependency:
  • Makedependency:
  • Build with:

Genie

  • Dependency: gtk3
  • Makedependency:
  • Build with:

Go

  • Dependency: gtk3
  • Makedependency: gotk3-gitAUR or
  • Build with: go build hello_world.go
  • (Or run with: )

Groovy

  • Dependencies: ,
  • Build with:
  • Run with: or
HelloWorld.groovy
import org.gnome.gtk.*
Gtk.init()
def Hello = new InfoMessageDialog(null, "Hello world!", "This is an example dialog.")
Hello.run()

Haskell

  • Dependency: gtk3
  • Makedependency:
  • Build with:
hello_world.hs
import Graphics.UI.Gtk
main = do
         initGUI
         dialog <- messageDialogNew Nothing [DialogModal] MessageInfo ButtonsOk "Hello world!"
         messageDialogSetSecondaryText dialog "This is an example dialog."
         _res <- dialogRun dialog
         return 0

IronPython

  • Dependencies: ,
  • Run with:

Java

  • Dependency:
  • Makedependency: java-environment
  • Build with:
  • Run with:

JavaScript

GJS:

  • Dependencies: gtk3,

Node.js:

JRuby

  • Dependencies: , jruby
  • Build with:
  • Run with: or

Julia

  • Dependencies: , Gtk.jl
  • Run with:

Jython

  • Dependencies: ,
  • Run with: jython -Dpython.path=/usr/share/java/gtk.jar hello_world.py

Kotlin

  • Dependency:
  • Makedependency:
  • Build with:
  • Run with:
HelloWorld.kt
import org.gnome.gtk.*

fun main(args : Array<String>) {
        Gtk.init(args);
        val Hello = InfoMessageDialog(null, "Hello world!", "This is an example dialog.");
        Hello.run();
}

Lua

  • Dependencies: gtk3,

Nemerle

  • Dependency:
  • Makedependency: nemerleAUR
  • Build with:
  • Run with:

OCaml

  • Dependency: gtk3
  • Makedependency:
  • Build with:

Pascal

Perl

  • Dependency:
hello_world.pl
#!/usr/bin/env perl
use Gtk3 -init;
my $hello = Gtk3::MessageDialog->new (undef, 'modal', 'info', 'ok', "Hello world!");
$hello->set ('secondary-text' => 'This is an example dialog.');
$hello->run;

Prolog

  • Dependency:
  • Run with:

Python

  • Dependencies: gtk3,

Ruby

  • Dependency:

Rust

Using Gtk-rs.

  • Dependency: gtk3
  • Makedependency: rust
  • Build with:
  • Run with: or

Scala

  • Dependency: (and )
  • Makedependency:
  • Build with:
  • Run with: (or scala -cp /usr/share/java/gtk.jar HelloWorld.scala)

Vala

  • Dependency: gtk3
  • Makedependency:
  • Build with:

Visual Basic

  • Dependency:
  • Makedependency: mono-basicAUR
  • Build with:
  • Run with:
gollark: Anyway, my cult is defined as the set of all members of the server.
gollark: If your thing is 700 lines and has javadocs, it's actually *bad* code.
gollark: I thought about it, so it's true.
gollark: Well, it's easier to get a new mug than to resurrect yourself.
gollark: They let you use an OTP code generator app too.

See also

This article is issued from Archlinux. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.