Write a hello world GUI program that closes itself after three seconds

Write a program in any language, so long as it has GUI support for a window system (cannot be text-consoles, etc., and must be a GUI/toolkit/window).

The program must say hello world in any manner (splash image, menu bar, status bar, title, video, message box, other widget stuff, etc.), so long as a GUI-compliant window appears and shows this text for three seconds. The person who can code this in the least amount of code used, counted in bytes, will take the cake.

• The comments here have degraded into a pointless argument. Please refrain from extended discussion in the comments; if necessary, you may use chat instead. All comments have been purged. – Doorknob May 21 '14 at 20:53
• It doesn't matter where the argument came from - all users should avoid participating in disputes that are clearly noise or going nowhere. – Doorknob May 21 '14 at 20:56
• Does it have to be "Hello world" or can it be "Hello_world"? – slebetman May 23 '14 at 7:56
• Also, must it exit gracefully? – slebetman May 23 '14 at 8:04
• you don't specify how the program has to be run? for instance does it have to be started up by itself or can it be something loaded up in a already running environment? – Jordon Biondo May 25 '14 at 17:02

Bash with xterm, 34

Uses the title of an xterm window to display "Hello World". Does close after 3 seconds.

xterm -T Hello\ World -e sleep\ 3


If displaying Hello_World (without a space) is allowed, you can save one char (xterm -T Hello_World -e sleep\ 3).

• I'm curious if you could get this to work with rxvt to shave off a byte. – Zwei Jul 13 '16 at 3:52

Legacy C/Xt/Motif (240)

Super old-school entry!

Link with -lXm -lXt -lX11, order matters.

Also curious if this works on other *nix platforms, because the XFlush is me subverting what I'm supposed to do (enter the application loop) in order that I don't have to install a timer to shut down after 3 seconds (and consume more characters).

#include <Xm/XmAll.h>
int main(int n,char **v){XtAppContext c;Widget t=XtVaAppInitialize(&c,"h",NULL,0,&n,v,NULL,NULL);XtVaSetValues(t,XmNtitle,"Hello World",XmNminWidth,300,NULL);XtRealizeWidget(t);XFlush(XtDisplay(t));sleep(3);return 0;}


TCL, 52 bytes

label .l -text Hello\ World
pack .l
after 3000 exit

• You can save bytes if you nest label into pack as: pack [label .l -text Hello\ World] – sergiol Nov 2 '17 at 23:45

Python with turtle module (69 66 bytes)

import turtle as t,time
t.title("Hello World")
t.fd(1)
time.sleep(3)


Note that if you run this in an interactive console, you don't need the t.fd(9) line. However, for some reason when running this non-interactively, the title doesn't change unless you run the extra line.

Edit (66 bytes)

import turtle as t
t.title("Hello World")
t.ontimer(t.fd(1),3000)


JavaScript (51)

Some old JavaScript methods that still exist because they existed in Netscape 2. document.write replaces the page with a string. setTimeout calls a function after given time (in miliseconds). close closes the window. Doesn't work in Firefox JS console, but it works when imported with <script> or in other browsers' JavaScript consoles.

document.write("Hello world")
setTimeout(close,3e3)


QML - 98 bytes

Here's the code. Works on all supported platforms (including Android and iOS):

import QtQuick 1.0;Text{text:"Hello world";Timer{interval:3000;onTriggered:Qt.quit();running:1>0}}


• I don't know QML, but can you change true into 1 or 1>0? – user12205 May 25 '14 at 8:54
• @ace qml wants boolean, so 1 didn't work for me, but as you suggested, 1>0 works fine 😄 thanks a bunch, squeezed one more byte 😃 – Eduard Sukharev May 25 '14 at 15:50

PureBasic, 91 chars

Okay, it's not the shortest, it will never win, but I still gotta support my favourite BASIC dialect :-)

OpenWindow(0,9,9,99,99,"")
Delay(3000)
CloseWindow(0)


PowerShell, 72 49

saps -pa notepad "Hello World"|%{sleep 3;kill $_}  Thanks to @joey for continued golfing • saps -pa notepad "Hello World"|%{sleep 3;kill$_} would be quite a bit shorter. – Joey May 25 '14 at 9:25

Java, 153 bytes

interface a{static void main(String[]A){new Thread(()->javax.swing.JOptionPane.showMessageDialog("Hello world")).start();Thread.sleep(3000);throw null;}}


Points to null three seconds after popping up a quite ugly window with the text "Hello world" on it.

SmileBASIC, 23 bytes

DIALOG"hello world",,,3


APL (Dyalog APL), 36 bytes

⎕EX(⎕DL 3)⊢⎕A⎕WC'Form' 'hello world'


⎕A  uppercase Alphabet (the only legal name which can be written with two characters)

⎕WCWindow Create (and return name of)

'Form' 'hello world' a GUI form with appropriate caption

⊢ yield the form's name while ignoring the result of

(⎕DL 3)Delaying 3 seconds (the ignored result is the elapsed time)

⎕EXExpunge the form (thus making it disappear)

This only works on Windows.

Autohotkey, 22 Bytes

msgbox,,hello world,,3


Ahk's msgbox is pretty powerful and has a built-in timeout option.

• 1 year late lol – MilkyWay90 Dec 30 '18 at 4:05

Ruby - 136 bytes

Using FXRuby :

require'fox16';include Fox;a=FXApp.new;timeout=a.addTimeout(3000)do|s|a.exit;end;a.create;FXMessageBox.error(a,MBOX_OK,'','Hello World')


VB.NET Winforms, 167

Private Sub Form2_Shown(sender As Object, e As System.EventArgs) Handles Me.Shown
Me.Text = "hello world"
End
End Sub


based on ace suggestion the new code is

NOW 100 Characters

 Sub f() Handles Me.Shown
Me.Text = "hello world"
End
End Sub

• You can golf it down a lot more. Start by reducing whitespace (e.g. use one space instead of 4 spaces for indentation, remove the spaces between the assignment operator). Try using single character identifiers, e.g. Sub F(s As Object,e As System.EventArgs)Handles Me.Shown (not sure whether you can replace sender). Try to remove Private and see if that works. – user12205 May 23 '14 at 10:24
• @ace you are correct, the new code is Sub f() Handles Me.Shown Me.Text = "hello world" System.Threading.Thread.Sleep(3000) End End Sub – sansknwoledge May 23 '14 at 12:41

Javascript (ECMAScript) + jQuery

65 Script + 23 Html = 88 Characters

Html

<div id='a'>Hello World


Script

e=$('#a'),d='dialog',x=e[d]();setTimeout(B=n=>{x.remove()},3000)  All-in-one (105 Characters) <div id='a'>Hello World<script>e=$('#a'),d='dialog',x=e[d]();setTimeout(B=n=>{x.remove()},3000)</script>

Fiddle

 <div id="a">Hello World
<script>
e=\$("#a"),
d='dialog',
x=e[d]();
setTimeout(B=n=>{x.remove()},3000)
</script>


Linux Shell, 54

echo "hello world">f;firefox f;sleep 3;killall firefox

• I tried "timeout 3 firefox Hello\ world" and it appeared to work, but then the next time I started firefox it reset itself to factory settings. – Glenn Randers-Pehrson May 24 '14 at 23:52

HTML/JavaScript (81)

<body onload="setTimeout(function(){document.body.innerHTML=''},3e3)">Hello World


Factor, 128 bytes

[ f T{ world-attributes { title "" } } clone "Hello world" <label> >>gadgets open-window* 3 seconds sleep close-window ] with-ui


Tcl/Tk, 15+11=26

after 3000 exit


If I name the file "Hello world.tcl", I will automatically get the "Hello world" text as the window's title:

• Unless you count the file name as part of your score, this violates this standard loophole. – caird coinheringaahing Nov 2 '17 at 23:35
• @cairdcoinheringaahing: fixed. I added the byte count of the file name without the .tcl part – sergiol Nov 2 '17 at 23:42