25
\$\begingroup\$

Please read the rules, and the bold areas as well.

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.

\$\endgroup\$
9
  • 1
    \$\begingroup\$ 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. \$\endgroup\$
    – Doorknob
    Commented May 21, 2014 at 20:53
  • 14
    \$\begingroup\$ It doesn't matter where the argument came from - all users should avoid participating in disputes that are clearly noise or going nowhere. \$\endgroup\$
    – Doorknob
    Commented May 21, 2014 at 20:56
  • 1
    \$\begingroup\$ Does it have to be "Hello world" or can it be "Hello_world"? \$\endgroup\$
    – slebetman
    Commented May 23, 2014 at 7:56
  • 4
    \$\begingroup\$ Also, must it exit gracefully? \$\endgroup\$
    – slebetman
    Commented May 23, 2014 at 8:04
  • \$\begingroup\$ 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? \$\endgroup\$ Commented May 25, 2014 at 17:02

53 Answers 53

29
\$\begingroup\$

Unix shell, 31 characters

xmessage -timeout 3 hello world

message "hello world" with button "okay"

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

\$\endgroup\$
4
  • \$\begingroup\$ Grrr...I was going to post one using timeout and zenity but it was longer... \$\endgroup\$
    – BenjiWiebe
    Commented May 23, 2014 at 15:21
  • \$\begingroup\$ @BenjiWiebe There is a zenity answer by n.1 at codegolf.stackexchange.com/a/28451/4065 \$\endgroup\$
    – kernigh
    Commented May 23, 2014 at 18:58
  • 2
    \$\begingroup\$ You can save 1 byte: timeout 3 xmessage hello world \$\endgroup\$ Commented May 24, 2014 at 14:41
  • 1
    \$\begingroup\$ @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? \$\endgroup\$
    – kernigh
    Commented May 24, 2014 at 19:09
24
\$\begingroup\$

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.

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

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'

enter image description here

\$\endgroup\$
1
  • \$\begingroup\$ Dang I just saw this! Nice answer. I had tell app "Terminal" to display dialog "Hello World" giving up after 3 for 70 bytes... \$\endgroup\$
    – roblogic
    Commented Aug 12 at 15:25
17
\$\begingroup\$

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

shell script, 31

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

notify-send -t 3000 Hello world

screenshot

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Probably not since it isn't a GUI compliant window. Unfortunately, using zenity is much longer. \$\endgroup\$
    – user80551
    Commented May 22, 2014 at 11:10
  • \$\begingroup\$ Its 34 chars with gedit - codegolf.stackexchange.com/a/28425/8766 \$\endgroup\$
    – user80551
    Commented May 22, 2014 at 11:13
  • 4
    \$\begingroup\$ 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). \$\endgroup\$
    – kernigh
    Commented May 23, 2014 at 19:07
12
\$\begingroup\$

shell + gedit / geany, 34

gedit Hello\ World&sleep 3;kill $!

Hello World in gedit

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

Hello World in geany

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 $!

Hello : World - Meld

\$\endgroup\$
9
  • \$\begingroup\$ Nice idea, gedit tries to open a file with this name even if there's no file. \$\endgroup\$
    – A.L
    Commented May 22, 2014 at 18:04
  • \$\begingroup\$ If you use gvim it will need only 33 chars \$\endgroup\$
    – avall
    Commented May 22, 2014 at 18:17
  • 1
    \$\begingroup\$ @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). \$\endgroup\$
    – user80551
    Commented May 23, 2014 at 12:34
  • 1
    \$\begingroup\$ Sorry, I was trying to be humorous. I was assuming the user has root permissions. \$\endgroup\$
    – Daniel
    Commented May 23, 2014 at 12:48
  • 1
    \$\begingroup\$ @Daniel No need to be sorry, this site is based on the most evil devious twisting of the rules to make your code shorter. \$\endgroup\$
    – user80551
    Commented May 23, 2014 at 13:02
7
\$\begingroup\$

VBScript, 58

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

screenshot

\$\endgroup\$
6
\$\begingroup\$

Python (pygame), 87

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

screenshot

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

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.

\$\endgroup\$
6
\$\begingroup\$

52 51 chars with Mathematica

(Hope it counts as a GUI-compliant.)

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

Mathematica GUI Golf code

\$\endgroup\$
5
\$\begingroup\$

GTK+, 47 45

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

Hello World


Old version (score 47):

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

Hello World

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

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

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:

enter image description here

Drag it bigger:

enter image description here


Expanded code (ie readable):

class F {

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

}
\$\endgroup\$
4
  • \$\begingroup\$ You can use enum instead of class to save another character. \$\endgroup\$
    – Riking
    Commented May 21, 2014 at 22:34
  • \$\begingroup\$ @Riking it doesn't work. \$\endgroup\$
    – Justin
    Commented May 21, 2014 at 22:35
  • \$\begingroup\$ Really? I could've sworn I actually used that once... Dang. \$\endgroup\$
    – Riking
    Commented May 21, 2014 at 22:36
  • 3
    \$\begingroup\$ @Riking codegolf.stackexchange.com/questions/6671/… \$\endgroup\$
    – Justin
    Commented May 21, 2014 at 22:36
4
\$\begingroup\$

R, 44

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

enter image description here

\$\endgroup\$
4
\$\begingroup\$

PowerShell - 63 52

(new-object -c wscript.shell).popup('Hello World',3)
\$\endgroup\$
4
\$\begingroup\$

Visual FoxPro - 23 characters

WAIT"hello world"TIME 3

Hello world in VFP

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
\$\endgroup\$
4
\$\begingroup\$

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.

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

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.

\$\endgroup\$
5
  • \$\begingroup\$ Good job. &#32&#32&#32&#32 \$\endgroup\$
    – Sut Dip
    Commented May 21, 2014 at 20:54
  • \$\begingroup\$ How does that even compile? 'SAFE' isn't a single char. \$\endgroup\$ Commented May 23, 2014 at 19:40
  • \$\begingroup\$ @heinrich5991 SAFE is likely defined in allegro.h as a single character. \$\endgroup\$
    – Adam Davis
    Commented May 23, 2014 at 21:28
  • \$\begingroup\$ @AdamDavis C evaluates macros in character constants? \$\endgroup\$ Commented May 24, 2014 at 13:34
  • 1
    \$\begingroup\$ 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 \$\endgroup\$ Commented May 25, 2014 at 15:38
3
\$\begingroup\$

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 ...

\$\endgroup\$
5
  • \$\begingroup\$ 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. \$\endgroup\$
    – Bob
    Commented May 23, 2014 at 5:02
  • \$\begingroup\$ 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) \$\endgroup\$
    – Num Lock
    Commented May 23, 2014 at 6:48
  • 1
    \$\begingroup\$ The consensus seems to be that you need to: meta.codegolf.stackexchange.com/questions/383/… meta.codegolf.stackexchange.com/questions/19/… meta.codegolf.stackexchange.com/questions/84/shebangs-yes-or-no \$\endgroup\$
    – Bob
    Commented May 23, 2014 at 7:38
  • \$\begingroup\$ 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. \$\endgroup\$
    – Bob
    Commented May 23, 2014 at 7:42
  • \$\begingroup\$ I will keep that in mind. Thank you for the references. \$\endgroup\$
    – Num Lock
    Commented May 23, 2014 at 7:54
3
\$\begingroup\$

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
\$\endgroup\$
3
\$\begingroup\$

Autohotkey, 22 Bytes

msgbox,,hello world,,3

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

msgbox

\$\endgroup\$
1
  • \$\begingroup\$ 1 year late lol \$\endgroup\$
    – MilkyWay90
    Commented Dec 30, 2018 at 4:05
3
\$\begingroup\$

Red, 49 bytes

view[text"hello world"rate 0:0:3 on-time[unview]]
\$\endgroup\$
2
\$\begingroup\$

APL (40)

X.Close⊣⎕DL 3⊣'X'⎕WC'Form' 'Hello World'
\$\endgroup\$
1
  • \$\begingroup\$ 39: X.Close⊣⎕DL⍴⍕'X'⎕WC'Form' 'Hello World' \$\endgroup\$
    – Adám
    Commented Jun 28, 2016 at 19:48
2
\$\begingroup\$

Lua + LÖVE, 67 bytes

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

enter image description here

\$\endgroup\$
2
\$\begingroup\$

Perl on Windows (56)

use Win32;fork?kill+sleep+3,$$:Win32'MsgBox"Hello World"
\$\endgroup\$
1
  • \$\begingroup\$ Use '-MWin32' to save four bytes \$\endgroup\$
    – user17752
    Commented Jun 6, 2017 at 8:49
2
\$\begingroup\$

Perl 5, 47

Using Perl/Tk:

perl -MTk -e'alarm 3;tkinit-title,"Hello World!";MainLoop'
#     123    45678901234567890123456789012345678901234567
\$\endgroup\$
6
  • \$\begingroup\$ It seems that the Tk module is required. \$\endgroup\$
    – A.L
    Commented May 22, 2014 at 18:03
  • 2
    \$\begingroup\$ Yes, of course you need some GUI toolkit. I choose Tk because of tkinit(). \$\endgroup\$
    – Matthias
    Commented May 23, 2014 at 5:57
  • \$\begingroup\$ I count 44 bytes. Are you counting the -MTk flag as well? \$\endgroup\$
    – slebetman
    Commented May 23, 2014 at 8:12
  • \$\begingroup\$ @slebetman Yes I count that as 3 chars, I added the count to the post. \$\endgroup\$
    – Matthias
    Commented May 23, 2014 at 8:15
  • 1
    \$\begingroup\$ @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. \$\endgroup\$
    – Matthias
    Commented May 23, 2014 at 13:35
2
\$\begingroup\$

Rebol View (r3gui), 49

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

"hello world" from Rebol 3 View

Ungolfed:

view/no-wait [title "hello world"]
wait 3
unview/all
\$\endgroup\$
2
\$\begingroup\$

Processing, 77

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

Screenshot:

enter image description here

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

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

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)
\$\endgroup\$
2
\$\begingroup\$

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}}

enter image description here

\$\endgroup\$
2
  • \$\begingroup\$ I don't know QML, but can you change true into 1 or 1>0? \$\endgroup\$
    – user12205
    Commented May 25, 2014 at 8:54
  • 1
    \$\begingroup\$ @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 😃 \$\endgroup\$ Commented May 25, 2014 at 15:50
2
\$\begingroup\$

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,"")
TextGadget(0,0,0,99,99,"Hello World")
Delay(3000)
CloseWindow(0)

Hello World picture

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.