24
\$\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\$
  • 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 May 21 '14 at 20:53
  • 13
    \$\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 May 21 '14 at 20:56
  • 1
    \$\begingroup\$ Does it have to be "Hello world" or can it be "Hello_world"? \$\endgroup\$ – slebetman May 23 '14 at 7:56
  • 3
    \$\begingroup\$ Also, must it exit gracefully? \$\endgroup\$ – slebetman May 23 '14 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\$ – Jordon Biondo May 25 '14 at 17:02

49 Answers 49

1
\$\begingroup\$

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

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

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;}
\$\endgroup\$
1
\$\begingroup\$

TCL, 52 bytes

label .l -text Hello\ World
pack .l
after 3000 exit
\$\endgroup\$
  • \$\begingroup\$ You can save bytes if you nest label into pack as: pack [label .l -text Hello\ World] \$\endgroup\$ – sergiol Nov 2 '17 at 23:45
1
\$\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\$
1
\$\begingroup\$

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)
\$\endgroup\$
1
\$\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\$
  • \$\begingroup\$ I don't know QML, but can you change true into 1 or 1>0? \$\endgroup\$ – ace May 25 '14 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\$ – Eduard Sukharev May 25 '14 at 15:50
1
\$\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\$
1
\$\begingroup\$

PowerShell, 72 49

saps -pa notepad "Hello World"|%{sleep 3;kill $_}

enter image description here

Thanks to @joey for continued golfing

\$\endgroup\$
  • \$\begingroup\$ saps -pa notepad "Hello World"|%{sleep 3;kill $_} would be quite a bit shorter. \$\endgroup\$ – Joey May 25 '14 at 9:25
1
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

SmileBASIC, 23 bytes

DIALOG"hello world",,,3

enter image description here

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

Autohotkey, 22 Bytes

msgbox,,hello world,,3

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

msgbox

\$\endgroup\$
  • \$\begingroup\$ 1 year late lol \$\endgroup\$ – MilkyWay90 Dec 30 '18 at 4:05
0
\$\begingroup\$

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

FXRuby

\$\endgroup\$
0
\$\begingroup\$

VB.NET Winforms, 167

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

based on ace suggestion the new code is

NOW 100 Characters

 Sub f() Handles Me.Shown
Me.Text = "hello world"
System.Threading.Thread.Sleep(3000)
End
End Sub
\$\endgroup\$
  • \$\begingroup\$ 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. \$\endgroup\$ – ace May 23 '14 at 10:24
  • \$\begingroup\$ @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 \$\endgroup\$ – sansknwoledge May 23 '14 at 12:41
0
\$\begingroup\$

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

Linux Shell, 54

echo "hello world">f;firefox f;sleep 3;killall firefox
\$\endgroup\$
  • \$\begingroup\$ 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. \$\endgroup\$ – Glenn Randers-Pehrson May 24 '14 at 23:52
0
\$\begingroup\$

HTML/JavaScript (81)

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

Factor, 128 bytes

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

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:

enter image description here

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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