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 May 21 '14 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 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
  • 4
    \$\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

53 Answers 53

1
2
2
\$\begingroup\$

PowerShell, 72 49

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

enter image description here

Thanks to @joey for continued golfing

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

SmileBASIC, 23 bytes

DIALOG"hello world",,,3

enter image description here

\$\endgroup\$
2
\$\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\$
2
\$\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 Dec 30 '18 at 4:05
2
\$\begingroup\$

C (MSVC) + Windows API, 130 119

-11 thanks to @EasyasPi

#include<windows.h>
main(){GetProcAddress(LoadLibrary("user32.dll"),"MessageBoxTimeoutA")(0,"Hello World",0,0,0,3000);}

Never thought the Windows API could get this short! Many thanks to this Stack Overflow answer for documenting the undocumented MessageBoxTimeoutA function.

Message box

\$\endgroup\$
1
  • \$\begingroup\$ -11 bytes if you use main() instead of WinMain(..), and use LoadLibrary instead of LoadLibraryA. \$\endgroup\$ – EasyasPi Jun 3 at 5:40
1
\$\begingroup\$

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.

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

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

Ruby [with Shoes] (44 chars)

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

osx app

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

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

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

Factor, 128 bytes

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

05AB1E + Message permission, 39 bytes

'‚«™’ÿ.¬•"ÄÖ/€º:3 * Ÿ™ ‚ï"’.E

'‚«™’...’.E  # trimmed program
         .E  # evaluate...
    ’...’    # "ÿ.shell\"msg/time:3 * hello world\""...
             # (implicit) with ÿ replaced by...
'‚«          # "system"...
   ™         # in title case...
         .E  # as Elixir code

====================

System.shell"..."  # trimmed program
System.shell       # execute shell command...
            "..."  # literal

====================

msg/time:3 * ...  # trimmed program
msg               # show message...
             ...  # literal...
   /time:         # that closes after...
         3        # literal...
   /time:         # seconds...
           *      # to all users
\$\endgroup\$
1
  • 1
    \$\begingroup\$ if it requires msg.exe, then you need to add that along with the language name. \$\endgroup\$ – Razetime Jun 5 at 5: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\$
2
  • \$\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\$ – user12205 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\$
1
  • \$\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\$

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

Vala + gtk+-3.0, 144 bytes

void main(string[]a){Gtk.init(ref a);var w=new Gtk.Window();w.title="hello world";w.show();Timeout.add(3000,()=>{Process.exit(0);});Gtk.main();}

First Vala program, first GTK program.

The title is hello world, but the default window size causes it to clip on my window manager.

enter image description here

void main(string[] args)
{
    // Initialize GTK
    Gtk.init(ref args);
    // Create a new window
    var win = new Gtk.Window();
    // Set the title
    win.title = "hello world";
    // Set the window to show
    win.show();
    // Set a timeout to exit the program after 3 seconds
    Timeout.add(3000, () => { Process.exit(0); });
    // Enter the main GTK loop to show the window
    Gtk.main();
}
\$\endgroup\$
1
2

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.