< 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 )
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: gtk-sharp-3
- Build with:
- Run with:
Clojure
- Dependencies: java-gnomeAUR,
- 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
- Dependency: gtk3
- Makedependencies: , crystal-gobject
- Build with:
D
- Dependency:
- Makedependency:
- Build with:
F#
- Dependency: dotnet-sdk
- 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: or
go get github.com/gotk3/gotk3/gtk
- Build with:
- (Or run with: )
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: , java-gnomeAUR
- Build with:
- Run with: or
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: gtk-sharp-3,
- Run with:
Java
- Dependency: java-gnomeAUR
- Makedependency: java-environment
- Build with:
javac -cp /usr/share/java/gtk.jar HelloWorld.java && jar cfe HelloWorld.jar HelloWorld HelloWorld.class
- Run with:
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: java-gnomeAUR,
- Build with:
- Run with: or
Julia
- Dependencies: , Gtk.jl
- Run with:
julia hello_world.jl
Jython
- Dependencies: java-gnomeAUR,
- Run with:
hello_world.py
from org.gnome.gtk import Gtk, InfoMessageDialog Gtk.init(None) Hello=InfoMessageDialog(None, "Hello world!", "This is an example dialog.") Hello.run()
Kotlin
- Dependency: java-gnomeAUR
- Makedependency:
- Build with:
- Run with:
Lua
- Dependencies: gtk3,
Nemerle
- Dependency: gtk-sharp-3
- Makedependency:
- Build with:
ncc -pkg:gtk-sharp-3.0 -out:hello_world.exe hello_world.n
- Run with:
Pascal
- Dependency: gtk3
- Makedependencies: , GTK 3.0 bindings
- Build with:
Perl
- Dependency:
Prolog
- Dependency: plgiAUR
- Run with:
Python
- Dependencies: gtk3,
Ruby
- Dependency: gtk3,
hello_world.rb
#!/usr/bin/env ruby require 'gir_ffi-gtk3' Gtk.init Hello = Gtk::MessageDialog.new nil, :modal, :info, :ok, "Hello world!" Hello.secondary_text = "This is an example dialog." Hello.run
- Dependency:
Rust
Using Gtk-rs.
- Dependency: gtk3
- Makedependency:
- Build with:
- Run with:
target/debug/hello_world
or
Scala
- Dependency: java-gnomeAUR (and )
- Makedependency:
- Build with:
- Run with: (or )
Vala
- Dependency: gtk3
- Makedependency:
- Build with:
valac --pkg gtk+-3.0 hello_world.vala
Visual Basic
- Dependency: gtk-sharp-3
- Makedependency:
- Build with:
vbnc -r:/usr/lib/mono/gtk-sharp-3.0/gtk-sharp.dll hello_world.vb
- 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.