Take the 2-minute tour ×
Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It's 100% free, no registration required.

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.

share|improve this question
1  
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 at 20:53
12  
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 at 20:56
1  
Does it have to be "Hello world" or can it be "Hello_world"? –  slebetman May 23 at 7:56
3  
Also, must it exit gracefully? –  slebetman May 23 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 at 17:02

45 Answers 45

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

share|improve this answer
    
Grrr...I was going to post one using timeout and zenity but it was longer... –  BenjiWiebe May 23 at 15:21
    
@BenjiWiebe There is a zenity answer by n.1 at codegolf.stackexchange.com/a/28451/4065 –  kernigh May 23 at 18:58
1  
You can save 1 byte: timeout 3 xmessage hello world –  Glenn Randers-Pehrson May 24 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 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.

share|improve this answer
    
Escape the space, use Hello\ World –  user80551 May 23 at 5:58
1  
@user80551 The question requires "Hello World" to be displayed in any manner, so that shouldn't be necessary. –  AsheeshR May 23 at 6:01
    
Technically, that would make this Hello <space> <close icon> <Document icon> World –  user80551 May 23 at 6:03
    
Can you confirm if kate would work instead of gedit? –  user80551 May 23 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 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'

enter image description here

share|improve this answer

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

screenshot

share|improve this answer
1  
Probably not since it isn't a GUI compliant window. Unfortunately, using zenity is much longer. –  user80551 May 22 at 11:10
    
Its 34 chars with gedit - codegolf.stackexchange.com/a/28425/8766 –  user80551 May 22 at 11:13
3  
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 at 19:07

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. http://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

share|improve this answer
    
Nice idea, gedit tries to open a file with this name even if there's no file. –  A.L May 22 at 18:04
    
If you use gvim it will need only 33 chars –  avall May 22 at 18:17
1  
@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 at 12:34
1  
Sorry, I was trying to be humorous. I was assuming the user has root permissions. –  Daniel May 23 at 12:48
1  
@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 at 13:02

VBScript, 58

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

screenshot

share|improve this answer

Python (pygame), 87

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

screenshot

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

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

}
share|improve this answer
    
You can use enum instead of class to save another character. –  Riking May 21 at 22:34
    
@Riking it doesn't work. –  Quincunx May 21 at 22:35
    
Really? I could've sworn I actually used that once... Dang. –  Riking May 21 at 22:36
3  

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.

share|improve this answer

52 51 chars with Mathematica

(Hope it counts as a GUI-compliant.)

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

Mathematica GUI Golf code

share|improve this answer

R, 44

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

enter image description here

share|improve this answer

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.

share|improve this answer
    
Good job. &#32&#32&#32&#32 –  Sut Dip May 21 at 20:54
    
How does that even compile? 'SAFE' isn't a single char. –  heinrich5991 May 23 at 19:40
    
@heinrich5991 SAFE is likely defined in allegro.h as a single character. –  Adam Davis May 23 at 21:28
    
@AdamDavis C evaluates macros in character constants? –  heinrich5991 May 24 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 at 15:38

PowerShell - 63 52

(new-object -c wscript.shell).popup('Hello World',3)
share|improve this answer

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

share|improve this answer
    
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 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 at 6:48
1  
    
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 at 7:42
    
I will keep that in mind. Thank you for the references. –  Num Lock May 23 at 7:54

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
share|improve this answer

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.

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

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.

share|improve this answer

Lua + LÖVE, 67 bytes

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

enter image description here

share|improve this answer

Perl on Windows (56)

use Win32;fork?kill+sleep+3,$$:Win32'MsgBox"Hello World"
share|improve this answer

Perl 5, 47

Using Perl/Tk:

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

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

share|improve this answer
3  
Using 9 for Y position instead of 10 works for me. –  ace May 23 at 10:16
    
Just edited the code. Thanks! –  segfaultd May 23 at 14:48
2  
Just noticed you can use 3e3 instead of 3000 to save one more char –  ace May 23 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
share|improve this answer

APL (40)

X.Close⊣⎕DL 3⊣'X'⎕WC'Form' 'Hello World'
share|improve this answer

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.

share|improve this answer
    
Same idea, different module: turtle has less bytes. =D codegolf.stackexchange.com/a/28548/14506 –  daviewales May 24 at 13:12

Cobra - 180

use System.Windows.Forms
use System.Threading
class M
    def main
        Thread(ref .w).start
        Thread.sleep(3000)
        Environment.exit(0)
    def w
        MessageBox.show("hello world")
share|improve this answer

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);}}
share|improve this answer

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
share|improve this answer

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

share|improve this answer

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)
share|improve this answer

protected by ace May 25 at 8:39

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

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