< 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
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
- Dependency: zenity
hello_world.sh
#!/bin/bash zenity --info --title='Hello world!' --text='This is an example dialog.'
BASIC
- Dependency: gtk3
- Makedependency: freebasic-gnomeheadersAUR
- Build with:
fbc hello_world.bas
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: gtk-sharp-3 (and )
- Makedependency:
- Build with:
- Run with: (or )
C
- Dependency: gtk3
- Build with:
gcc -o hello_world $(pkg-config --cflags --libs gtk+-3.0) hello_world.c
C++
- Dependency:
- Build with:
g++ -o hello_world $(pkg-config --cflags --libs gtkmm-3.0) hello_world.cc
C#
- Dependency: gtk-sharp-3
- Build with:
- Run with:
Clojure
- Dependencies: ,
- Run with:
src/hello_world/core.clj
(ns hello-world.core (:import [org.gnome.gtk Gtk InfoMessageDialog])) (defonce gtk-init (Gtk/init (make-array String 0))) (defn -main [] (doto (InfoMessageDialog. nil "Hello world!" "This is an example dialog.").run))
Crystal
- Dependency: gtk3
- Makedependencies: , crystal-gobject
- Build with:
D
- Dependency:
- Makedependency:
- Build with:
hello_world.d
import gtk.Main;
import gtk.MessageDialog;
void main(string[] args)
{
Main.init(args);
MessageDialog dialog = new MessageDialog(null, GtkDialogFlags.MODAL, MessageType.INFO, ButtonsType.OK, "Hello world!");
dialog.run();
}
F#
- Dependency:
- Run with:
Fortran
- Dependency: gtk-3-fortran-gitAUR
- Makedependency:
- Build with:
Genie
- Dependency: gtk3
- Makedependency:
- Build with:
Go
hello_world.go
package main
import ("github.com/gotk3/gotk3/gtk")
func main() {
gtk.Init(nil)
dialog := gtk.MessageDialogNew(nil, gtk.DIALOG_MODAL, gtk.MESSAGE_INFO, gtk.BUTTONS_OK, "Hello world!")
dialog.FormatSecondaryText("This is an example notification.")
dialog.Run()
}
Groovy
- Dependencies: ,
- Build with:
- Run with: or
Haskell
- Dependency: gtk3
- Makedependency:
- Build with:
ghc hello_world
IronPython
- Dependencies: gtk-sharp-3,
- Run with:
Java
- Dependency:
- Makedependency: java-environment
- Build with:
- Run with:
HelloWorld.java
import org.gnome.gtk.Gtk;
import org.gnome.gtk.Dialog;
import org.gnome.gtk.InfoMessageDialog;
public class HelloWorld {
public static void main(String[] args) {
Gtk.init(args);
Dialog Hello = new InfoMessageDialog(null, "Hello world!", "This is an example dialog.");
Hello.run();
}
}
JavaScript
GJS:
- Dependencies: gtk3,
Node.js:
hello_world.js
#!/usr/bin/env node
const gi = require('node-gtk')
const Gtk = gi.require('Gtk', '3.0')
Gtk.init()
const Hello = new Gtk.MessageDialog({type: Gtk.MessageType.INFO,
buttons: Gtk.ButtonsType.OK,
text: "Hello world!",
"secondary-text": "This is an example dialog."})
Hello.run()
JRuby
- Dependencies: ,
- Build with:
- Run with: or
Julia
- Dependencies: , Gtk.jl
- Run with:
hello_world.jl
using Gtk
info_dialog("Hello world!\n\nThis is an example dialog.")
Jython
- Dependencies: ,
- Run with:
Kotlin
- Dependency:
- Makedependency:
- Build with:
kotlinc -cp /usr/share/java/gtk.jar HelloWorld.kt -include-runtime -d HelloWorld.jar - Run with:
Lua
- Dependencies: gtk3,
Nemerle
- Dependency: gtk-sharp-3
- Makedependency:
- Build with:
- Run with:
hello_world.n
using Gtk;
public class HelloWorld {
static Main() : void {
Application.Init ();
def Hello = MessageDialog (null, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, "Hello world!");
Hello.SecondaryText = "This is an example dialog.";
_ = Hello.Run ();
}
}
OCaml
- Dependency: gtk3
- Makedependency:
- Build with:
Pascal
- Dependency: gtk3
- Makedependencies: , GTK 3.0 bindings
- Build with:
Perl
- Dependency: perl-gtk3
Prolog
- Dependency:
- Run with:
hello_world.pl
:- use_module(library(plgi)).
:- plgi_use_namespace('Gtk').
main :-
g_object_new('GtkMessageDialog',
['message-type'='GTK_MESSAGE_INFO',
'buttons'='GTK_BUTTONS_OK',
'text'='Hello world!',
'secondary-text'='This is an example dialog.'],
Dialog),
gtk_dialog_run(Dialog, _),
halt.
:- main.
Python
- Dependencies: gtk3,
Ruby
- Dependency: gtk3,
- Dependency:
hello_world.rb
#!/usr/bin/env ruby
require 'gtk3'
Gtk.init
Hello = Gtk::MessageDialog.new(:type => :info,
:buttons_type => :ok,
:message => "Hello world!")
Hello.secondary_text = "This is an example dialog."
Hello.run
Scala
- Dependency: (and )
- Makedependency:
- Build with:
scalac -cp /usr/share/java/gtk.jar -d HelloWorld.jar HelloWorld.scala - Run with: (or )
Vala
- Dependency: gtk3
- Makedependency:
- Build with:
Visual Basic
- Dependency: gtk-sharp-3
- Makedependency: mono-basicAUR
- Build with:
- Run with:
This article is issued from Archlinux. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.