# 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

# Unix shell, 31 characters

xmessage -timeout 3 hello world


This program requires the xmessage(1) utility from X.Org. It uses the traditional black-and-white X Athena Widgets (Xaw).

• Grrr...I was going to post one using timeout and zenity but it was longer... – BenjiWiebe May 23 '14 at 15:21
• @BenjiWiebe There is a zenity answer by n.1 at codegolf.stackexchange.com/a/28451/4065 – kernigh May 23 '14 at 18:58
• You can save 1 byte: timeout 3 xmessage hello world – Glenn Randers-Pehrson May 24 '14 at 14:41
• @GlennRanders-Pehrson I can't do that, because my machine has no timeout command. Maybe someone else can post a new answer that uses it? – kernigh May 24 '14 at 19:09

# Shell and gedit - 27 characters

timeout 3 gedit Hello World


If Hello World needs to be displayed as a single string, then its 28 characters:

timeout 3 gedit Hello\ World


timeout utility runs a command for the duration specified. It ensures that gedit runs for 3 seconds, assuming minimal startup time.

Any editor can be used in place of gedit. If a shorter named editor is used like gvim, the length can be reduced by 1 or more characters.

Using an editor initially thought of by user80551.

• Escape the space, use Hello\ World – user80551 May 23 '14 at 5:58
• @user80551 The question requires "Hello World" to be displayed in any manner, so that shouldn't be necessary. – asheeshr May 23 '14 at 6:01
• Technically, that would make this Hello <space> <close icon> <Document icon> World – user80551 May 23 '14 at 6:03
• Can you confirm if kate would work instead of gedit? – user80551 May 23 '14 at 6:04
• @user80551 Dont have KDE installed, but going by Kate's man page, there doesnt seem to be any reason why it shouldn't work. – asheeshr May 23 '14 at 6:07

# Applescript, 45 bytes:

Not often Applescript is one of the shorter answers:

display alert "hello world" giving up after 3


Paste into the Applescript Editor and run, or run using osascript at the command line:

osascript -e 'display alert "hello world" giving up after 3'


# HTML+Javascript, 73 60 characters

<script>setTimeout("open('','_self','');close()",3e3)</script>Hello world


This works in Chrome, but may not be portable to other browsers.

Suggestions from the comments take this further:

<body onload=open('',name=setTimeout(close,3e3))>Hello world

• That's a lot of golfing I saw. I saw this go from 108 chars down to 73. Suddenly, the whole code is visible. – Justin May 21 '14 at 21:11
• @Quincunx: You missed the first few iterations then. :) – Greg Hewgill May 21 '14 at 21:11
• That's because I was busy posting my own code. :-) – Justin May 21 '14 at 21:12
• <body onload=open('','_self'),setTimeout(close,3e3)>Hello world seems to save a few more characters. – Ventero May 21 '14 at 22:40
• You have an edit suggestion from user3082537: save two chars by <body onload=open('',name=setTimeout(close,3e3))>Hello world – Justin May 23 '14 at 6:48

## shell script, 31

Not sure whether it qualifies. Requires notify-send. Works at least on Ubuntu 12.04.

notify-send -t 3000 Hello world


• Probably not since it isn't a GUI compliant window. Unfortunately, using zenity is much longer. – user80551 May 22 '14 at 11:10
• Its 34 chars with gedit - codegolf.stackexchange.com/a/28425/8766 – user80551 May 22 '14 at 11:13
• I believe that a window with no window decorations is still a window. Here in Enlightenment, the notification also has an X button to close it (but no other window decorations). – kernigh May 23 '14 at 19:07

gedit Hello\ World&sleep 3;kill $!  This assumes that gedit pops up instantly since the 3 seconds are counted from the start of issuing the command. Could be smaller if there's a GUI text editor shorter than gedit. geany works too for the same number of chars, just s/gedit/geany/g EDIT: Using timeout is shorter. https://codegolf.stackexchange.com/a/28477/8766 EDIT2: Can anyone confirm if this works with kate ? ## meld , 32 If exactly Hello World is not required, then meld can be used. meld Hello World&sleep 3;kill$!


• Nice idea, gedit tries to open a file with this name even if there's no file. – A.L May 22 '14 at 18:04
• If you use gvim it will need only 33 chars – avall May 22 '14 at 18:17
• @Daniel halt would be shorter but I don't know if being destructive is allowed. Also, it requires root permissions so we either need to assume that we are root or use sudo which costs more (and needs the user to type the password). – user80551 May 23 '14 at 12:34
• Sorry, I was trying to be humorous. I was assuming the user has root permissions. – Daniel May 23 '14 at 12:48
• @Daniel No need to be sorry, this site is based on the most evil devious twisting of the rules to make your code shorter. – user80551 May 23 '14 at 13:02

## VBScript, 58

WScript.CreateObject("WScript.Shell").Popup"Hello world",3


## Python (pygame), 87

import pygame.display as d,time
d.set_mode()
d.set_caption('Hello world')
time.sleep(3)


• Not working on OSX, doesn't show window... – Harry Beadle May 22 '14 at 11:21
• @BritishColour it should, perhaps it's too small? Try changing the size to [999,999] – user12205 May 22 '14 at 11:23
• Still not working, the window isn't even appearing... – Harry Beadle May 22 '14 at 11:26
• @BritishColour Well it definitely works for me. See here. Perhaps it was showing up at the background or something? – user12205 May 22 '14 at 11:40
• It's interesting how our code is basically identical, but uses a different module. tkinter turns out to be shorter. – Justin May 22 '14 at 16:06

## Tcl - 32 bytes

I noticed that some of these submissions, like the shell or javascript ones, allow you to type the code into the console. If that's the case I can shorten it to:

wm ti . hello\ world;af 3000 exi


Must be typed into the console after running wish. Meaning, run wish without arguments which will give you a REPL console and then type the code above. This makes use of the fact that tcl can be lenient and autocomplete command/function names but only in interactive mode. So that af actually exectues the after command and exi executes exit. I wanted to use ex but my system has the ex editor installed.

## Original submission - 36 bytes

wm ti . hello\ world;after 3000 exit


Run using wish instead of tclsh.

## 52 51 chars with Mathematica

(Hope it counts as a GUI-compliant.)

NotebookClose/@{CreateDialog@"Hello world",Pause@3}


# Java, 136 bytes

class F{public static void main(String[]a)throws Exception{new java.awt.Frame("Hello World").show();Thread.sleep(3000);System.exit(0);}}


Displays the message Hello World as the title of a frame. After 3 seconds, the program closes.

Looks like this:

Drag it bigger:

class F {

public static void main(String[] a) throws Exception {
new java.awt.Frame("Hello World").show();
System.exit(0);
}

}

• You can use enum instead of class to save another character. – Riking May 21 '14 at 22:34
• @Riking it doesn't work. – Justin May 21 '14 at 22:35
• Really? I could've sworn I actually used that once... Dang. – Riking May 21 '14 at 22:36
• – Justin May 21 '14 at 22:36

## R, 44

x11(ti="Hello World");Sys.sleep(3);dev.off()


## PowerShell - 63 52

(new-object -c wscript.shell).popup('Hello World',3)


# Visual FoxPro - 23 characters

WAIT"hello world"TIME 3


This abuses the fact that VFP allows to not to put a space between the string to be printed (which I just discovered) and that it allows to shorten every keyword to up to its first 4 characters.

Ungolfed version:

WAIT "hello world" TIMEOUT 3


# GTK+, 47 45

zenity --info --text=Hello\ World --timeout=3


Old version (score 47):

zenity --info --title="Hello World" --timeout=3


For some reason, zenity display a text which can be translated as All update are done.

• Just to add some extra info, All updates are complete. is what I get in English. – user12205 May 22 '14 at 18:50
• You can reduce one character by changing --title to --text – asheeshr May 23 '14 at 3:59
• You can change "Hello World" to Hello\ World – kernigh May 23 '14 at 19:00
• Thanks AsheeshR and kernigh, I have 2 less characters with your help. – A.L May 23 '14 at 19:47

## C, 151 characters

#include<allegro.h>
main(){textout_ex(screen,font,"Hello World",0,0,7,set_gfx_mode('SAFE',8,8,install_timer(),
allegro_init()));rest(3e3);}END_OF_MAIN()


Not the smallest answer. I like it though.

• Good job. &#32&#32&#32&#32 – Sut Dip May 21 '14 at 20:54
• How does that even compile? 'SAFE' isn't a single char. – heinrich5991 May 23 '14 at 19:40
• @heinrich5991 SAFE is likely defined in allegro.h as a single character. – Adam Davis May 23 '14 at 21:28
• @AdamDavis C evaluates macros in character constants? – heinrich5991 May 24 '14 at 13:34
• No macro, it's really just a 32-bit integer written as four bytes in what's called multi-character constant notation, a too-clever-for-its-own-good way to write four-byte tag strings. Apple used it for file type magic numbers once. Compilers nowadays support it but emit a warning. Example for nonbelievers – Wander Nauta May 25 '14 at 15:38

# C# 101 151

This will for sure not be the shortest answer (since there are already other good answers being way shorter) but codegolf.SE needs a lot more C# contributions in my opinion!

using t=System.Threading;class P{static void Main(){using(t.Tasks.Task.Run(()=>System.Windows.MessageBox.Show("hello world"))){t.Thread.Sleep(3000);}}}


# C# 121

An alternative based on Bob's answer, but with WPF instead of WinForms:

class P{static void Main(){new System.Windows.Window(){Title="hello world"}.Show();System.Threading.Thread.Sleep(3000);}}


Saves 3 characters thanks to the shorter namespace ...

• You need to include the using declarations in the character count. Alternatively, you could leave them out but then you'd have to do things like System.Windows.Forms.MessageBox.Show (slightly fewer characters if it's only a single use). As your code currently is, it won't compile or run. – Bob May 23 '14 at 5:02
• Well, I just assumed it was not neccesary because I see a lot of answers in C, C++, C#, Java etc without any using/imports/whatever. I will edit it, though. BTW, is there some explicit rule on this? Sure it would compile and run with the right compile settings and/or compiler. (e. g. resolving using directives on compile time, as long as they can be resolved distinct) – Num Lock May 23 '14 at 6:48
• It is a little grey - for example, I had to add a reference to System.Windows.Forms.dll, which is part of the msbuild config/the compile command line. However, the general consensus seems to be that when a full program is requested, using/import/#include/etc. where necessary for the code to compile and run are required, and attempting to use compiler command line tricks to dodge that is bad. – Bob May 23 '14 at 7:42
• I will keep that in mind. Thank you for the references. – Num Lock May 23 '14 at 7:54

## Batch (24)

msg/time:3 * hello world


Tested on Windows 7, but should work on any NT-based version of Windows, assuming you have MSG.EXE in your System32 folder.

EDIT: Apparently MSG.EXE is not available by default on home versions of Windows. On Windows 7, for example, this is only available in the Ultimate or Business editions. However, you can copy the file over to your System32 folder and get it to work. (You must also copy over the appropriate MSG.EXE.MUI file to get proper error messages, but my "script" works without them.)

You have to install software for most of these other responses to work, too, so I don't think that should be a disqualifier.

• Why won't this call a program named time:3 in a folder called msg in the current directory? – cat Jul 12 '16 at 23:11
• @cat Windows uses \. – jimmy23013 Jun 6 '17 at 5:16
• @jimmy wow that was a year ago. i'm just used to writing / on all platforms now oops – cat Jun 6 '17 at 10:40
• @jimmy23013 But Windows supports / too – MilkyWay90 Dec 30 '18 at 3:56
• @MilkyWay90 Windows supports / in some places, but in cmd, /xxx is interpreted as an argument. – jimmy23013 Dec 30 '18 at 5:52

## APL (40)

X.Close⊣⎕DL 3⊣'X'⎕WC'Form' 'Hello World'

• 39: X.Close⊣⎕DL⍴⍕'X'⎕WC'Form' 'Hello World' – Adám Jun 28 '16 at 19:48

## Lua + LÖVE, 67 bytes

l=love l.window.setTitle"hello world"l.timer.sleep(3)l.event.quit()


# Perl on Windows (56)

use Win32;fork?kill+sleep+3,:Win32'MsgBox"Hello World"

• Use '-MWin32' to save four bytes – DarkHeart Jun 6 '17 at 8:49

## Perl 5, 47

Using Perl/Tk:

perl -MTk -e'alarm 3;tkinit-title,"Hello World!";MainLoop'
#     123    45678901234567890123456789012345678901234567

• It seems that the Tk module is required. – A.L May 22 '14 at 18:03
• Yes, of course you need some GUI toolkit. I choose Tk because of tkinit(). – Matthias May 23 '14 at 5:57
• I count 44 bytes. Are you counting the -MTk flag as well? – slebetman May 23 '14 at 8:12
• @slebetman Yes I count that as 3 chars, I added the count to the post. – Matthias May 23 '14 at 8:15
• @n.1 I added it below the title with a link to the CPAN documentation of the Tk module. None of the perl core modules is a GUI module, therefore you always have to install external modules. Sorry, this was clear to me (as I am working with perl quite often), but you are right, it is surprising for those who work in other languages. – Matthias May 23 '14 at 13:35

# Rebol View (r3gui), 49

view/no-wait[title"hello world"]wait 3 unview/all


Ungolfed:

view/no-wait [title "hello world"]
wait 3
unview/all


# Processing, 77

int x=millis();void draw(){text("Hello world",0,9);if(millis()>x+3e3)exit();}


Screenshot:

Edit 1: Y position of the text can be 9 instead of 10, like noted by @ace.

Edit 2: 3000 can be represented as 3e3 to shave one character off, also noted by @ace

• Using 9 for Y position instead of 10 works for me. – user12205 May 23 '14 at 10:16
• Just edited the code. Thanks! – segfaultd May 23 '14 at 14:48
• Just noticed you can use 3e3 instead of 3000 to save one more char – user12205 May 23 '14 at 17:11

## bash + ImageMagick (36 bytes)

timeout 3 display label:Hello\ world


Tested on Ubuntu 14.04 LTS and on Fedora 20.

Nicer-looking, but 10 bytes larger:

timeout 3 display -size 800 label:Hello\ world


## CMD / Batch - 33 Bytes

I believe the window that the Windows CMD terminal runs in counts as GUI compliant.

start "Hello world" cmd /csleep 3


If you don't have the sleep command on your system - then you can use timeout which comes default in Windows 7. For two more bytes.

start "Hello world" cmd /ctimeout 3


Starts a new CMD window with the title "Hello World" (NOT displayed in the terminal itself, but as the title of the GUI window that the terminal runs in), this window will close as soon as all parsed commands have executed - so after sleep 3 or timeout 3 has completed.

The window looks like this -

Note; start runs the given commands in a new window - not the window that you are running the above commands from.

• Changing it to cmd "Hello world" cmd /ctimeout 3 puts Hello world in the title bar for 3 seconds, but that probably doesn't count. – Chris Kent May 26 '14 at 7:15
• I wouldn't think it does, because it doesn't spawn a new window. The question says a GUI-compliant window appears (appears being the key word), implying that it has to display a new window. Good idea though. – unclemeat May 26 '14 at 22:50
• start "Hello world" You sir, are a genius. – user8397947 Jul 13 '16 at 1:26

# Python 3, 83 72 bytes

from tkinter import*
f=Tk()
f.wm_title("Hello World")
f.after(3000,exit)


Save bytes by using tkinter.

The old method added a Label to the frame. This method sets the title of the frame to Hello World. f.after(3000,exit) runs exit() after 3000 milliseconds have passed.

# Cobra - 180

use System.Windows.Forms
class M
def main
Environment.exit(0)
def w
MessageBox.show("hello world")


# Ruby [with Shoes] (44 chars)

Shoes.app{para "Hello world";every(3){exit}}


# C# 124

Far from the shortest :(

class P{static void Main(){new System.Windows.Forms.Form(){Text="Hello World"}.Show();System.Threading.Thread.Sleep(3000);}}