Write a hello world GUI program that closes itself after three seconds

24

5

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.

Sut Dip

Posted 2014-05-21T20:28:28.333

Reputation: 383

Possible duplicate of "Hello, World!"

– Mego – 2016-07-13T00:24:36.697

Does the GUI window need to close, or is it enough that the words 'hello world' are replaced? – Adám – 2017-02-06T13:02:12.940

Is outputting "hllowrld" acceptable? – MilkyWay90 – 2018-12-30T04:02:07.333

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 – 2014-05-21T20:53:45.983

13It doesn't matter where the argument came from - all users should avoid participating in disputes that are clearly noise or going nowhere. – Doorknob – 2014-05-21T20:56:35.533

1Does it have to be "Hello world" or can it be "Hello_world"? – slebetman – 2014-05-23T07:56:19.323

3Also, must it exit gracefully? – slebetman – 2014-05-23T08:04:01.100

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 – 2014-05-25T17:02:37.237

So what's the etiquette for accepting answers on code golfing questions? This question has been open for ~ four months. – unclemeat – 2014-08-29T05:01:25.493

Answers

28

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

kernigh

Posted 2014-05-21T20:28:28.333

Reputation: 2 615

Grrr...I was going to post one using timeout and zenity but it was longer... – BenjiWiebe – 2014-05-23T15:21:39.733

@BenjiWiebe There is a zenity answer by n.1 at http://codegolf.stackexchange.com/a/28451/4065

– kernigh – 2014-05-23T18:58:47.780

2You can save 1 byte: timeout 3 xmessage hello world – Glenn Randers-Pehrson – 2014-05-24T14:41:18.397

1@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 – 2014-05-24T19:09:49.737

23

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.

asheeshr

Posted 2014-05-21T20:28:28.333

Reputation: 331

Escape the space, use Hello\ World – user80551 – 2014-05-23T05:58:46.263

1@user80551 The question requires "Hello World" to be displayed in any manner, so that shouldn't be necessary. – asheeshr – 2014-05-23T06:01:47.250

Technically, that would make this Hello <space> <close icon> <Document icon> World – user80551 – 2014-05-23T06:03:45.280

Can you confirm if kate would work instead of gedit? – user80551 – 2014-05-23T06:04:22.333

@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 – 2014-05-23T06:07:49.037

@user80551: It does work in kate, although the display looks a bit different.

– Ilmari Karonen – 2014-05-23T10:05:24.080

@IlmariKaronen I think that's because it's creating two separate documents. Did you escape the space i.e. Hello\ World instead of Hello World? – user80551 – 2014-05-23T10:18:09.320

@user80551: No I did not. Obviously, with an escaped space it would appear on one line (but then you lose the one-char advantage over gedit). – Ilmari Karonen – 2014-05-23T10:26:23.180

19

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

Digital Trauma

Posted 2014-05-21T20:28:28.333

Reputation: 64 644

17

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

Greg Hewgill

Posted 2014-05-21T20:28:28.333

Reputation: 2 641

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 – 2014-05-21T21:11:18.977

@Quincunx: You missed the first few iterations then. :) – Greg Hewgill – 2014-05-21T21:11:54.327

That's because I was busy posting my own code. :-) – Justin – 2014-05-21T21:12:22.217

For some reason, I see the string for much longer than 3 seconds (it doesn't close). – Justin – 2014-05-21T21:15:05.927

I tried in Firefox and IE and they both have stronger restrictions on web pages closing their own windows. – Greg Hewgill – 2014-05-21T21:15:47.063

I'm using chrome. I also tried jsfiddle. – Justin – 2014-05-21T21:17:58.253

2<body onload=open('','_self'),setTimeout(close,3e3)>Hello world seems to save a few more characters. – Ventero – 2014-05-21T22:40:28.167

-1 more byte from @Ventero 's version: <body onload=open('',name=0),setTimeout(close,3e3)>Hello world – nderscore – 2014-05-22T18:48:36.330

1You have an edit suggestion from user3082537: save two chars by <body onload=open('',name=setTimeout(close,3e3))>Hello world – Justin – 2014-05-23T06:48:12.383

Can't you just do <body onload=setTimeout(close,3e3))>Hello world or am I missing something here? – Danny – 2014-05-23T16:05:34.593

@Danny Only windows that have been explicitly opened with open can be closed by calling close on them. – Ventero – 2014-05-23T19:36:03.123

@Ventero oh. It worked for me in IE9 and Chrome. Guess they aren't following the rules. – Danny – 2014-05-23T20:00:36.027

@Danny It doesn't work in Chrome for me (after removing the extra )): Scripts may close only the windows that were opened by it.. – Ventero – 2014-05-23T20:03:44.643

@Ventero odd, I'm on 35.0.1916.114 m and it works. Maybe I have a setting somewhere that is allowing it. – Danny – 2014-05-23T21:41:04.273

16

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

user12205

Posted 2014-05-21T20:28:28.333

Reputation: 8 752

1Probably not since it isn't a GUI compliant *window*. Unfortunately, using zenity is much longer. – user80551 – 2014-05-22T11:10:16.320

Its 34 chars with gedit - http://codegolf.stackexchange.com/a/28425/8766

– user80551 – 2014-05-22T11:13:59.523

4I 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 – 2014-05-23T19:07:35.190

12

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

user80551

Posted 2014-05-21T20:28:28.333

Reputation: 2 520

Nice idea, gedit tries to open a file with this name even if there's no file. – A.L – 2014-05-22T18:04:50.390

If you use gvim it will need only 33 chars – avall – 2014-05-22T18:17:21.237

Its 27 chars using timeout http://codegolf.stackexchange.com/a/28477/8395

– asheeshr – 2014-05-23T05:56:18.897

@avall For some weird reason, the actually gvim process is getting started after 3 PIDs so it isn't getting killed. See http://pastebin.com/5PVgf9fm

– user80551 – 2014-05-23T05:57:35.917

Good answer. I tried Kate,it gives error: QDBusConnection. – bacchusbeale – 2014-05-23T09:49:14.360

reboot saves a character compared to kill $! – Daniel – 2014-05-23T12:31:56.553

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 – 2014-05-23T12:34:49.613

1Sorry, I was trying to be humorous. I was assuming the user has root permissions. – Daniel – 2014-05-23T12:48:14.570

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 – 2014-05-23T13:02:16.197

7

VBScript, 58

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

screenshot

user12205

Posted 2014-05-21T20:28:28.333

Reputation: 8 752

6

Python (pygame), 87

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

screenshot

user12205

Posted 2014-05-21T20:28:28.333

Reputation: 8 752

Use from pygame.display import * – Mega Man – 2016-06-25T08:51:55.743

Not working on OSX, doesn't show window... – Harry Beadle – 2014-05-22T11:21:08.577

@BritishColour it should, perhaps it's too small? Try changing the size to [999,999] – user12205 – 2014-05-22T11:23:28.867

Still not working, the window isn't even appearing... – Harry Beadle – 2014-05-22T11:26:22.107

@BritishColour Well it definitely works for me. See here. Perhaps it was showing up at the background or something?

– user12205 – 2014-05-22T11:40:45.067

What does the d.set_mode([200,9]) do? If it is just to make the window big enough, I don't think it is necessary (provided a window appears). – Justin – 2014-05-22T15:52:36.413

@Quincunx set_mode is needed to make the window appear. But it turns out the dimensions are not needed. Thanks. – user12205 – 2014-05-22T16:00:46.593

1It's interesting how our code is basically identical, but uses a different module. tkinter turns out to be shorter. – Justin – 2014-05-22T16:06:48.213

6

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.

slebetman

Posted 2014-05-21T20:28:28.333

Reputation: 629

5

52 51 chars with Mathematica

(Hope it counts as a GUI-compliant.)

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

Mathematica GUI Golf code

akater

Posted 2014-05-21T20:28:28.333

Reputation: 151

4

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

}

Justin

Posted 2014-05-21T20:28:28.333

Reputation: 19 757

You can use enum instead of class to save another character. – Riking – 2014-05-21T22:34:01.287

@Riking it doesn't work. – Justin – 2014-05-21T22:35:40.383

Really? I could've sworn I actually used that once... Dang. – Riking – 2014-05-21T22:36:32.917

4

R, 44

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

enter image description here

ping

Posted 2014-05-21T20:28:28.333

Reputation: 590

4

PowerShell - 63 52

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

Rynant

Posted 2014-05-21T20:28:28.333

Reputation: 2 353

4

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.

A.L

Posted 2014-05-21T20:28:28.333

Reputation: 1 245

1Just to add some extra info, All updates are complete. is what I get in English. – user12205 – 2014-05-22T18:50:25.650

1You can reduce one character by changing --title to --text – asheeshr – 2014-05-23T03:59:40.623

1You can change "Hello World" to Hello\ World – kernigh – 2014-05-23T19:00:24.747

Thanks AsheeshR and kernigh, I have 2 less characters with your help. – A.L – 2014-05-23T19:47:30.283

4

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

Alejandro

Posted 2014-05-21T20:28:28.333

Reputation: 161

3

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.

Oberon

Posted 2014-05-21T20:28:28.333

Reputation: 2 881

Good job. – Sut Dip – 2014-05-21T20:54:02.467

How does that even compile? 'SAFE' isn't a single char. – heinrich5991 – 2014-05-23T19:40:55.797

@heinrich5991 SAFE is likely defined in allegro.h as a single character. – Adam Davis – 2014-05-23T21:28:53.007

@AdamDavis C evaluates macros in character constants? – heinrich5991 – 2014-05-24T13:34:48.597

1

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 – 2014-05-25T15:38:20.930

3

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

Num Lock

Posted 2014-05-21T20:28:28.333

Reputation: 211

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 – 2014-05-23T05:02:42.430

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 – 2014-05-23T06:48:22.167

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 – 2014-05-23T07:42:09.043

I will keep that in mind. Thank you for the references. – Num Lock – 2014-05-23T07:54:53.290

3

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.

trlkly

Posted 2014-05-21T20:28:28.333

Reputation: 178

Why won't this call a program named time:3 in a folder called msg in the current directory? – cat – 2016-07-12T23:11:18.593

@cat Windows uses \. – jimmy23013 – 2017-06-06T05:16:13.220

@jimmy wow that was a year ago. i'm just used to writing / on all platforms now oops – cat – 2017-06-06T10:40:09.050

@jimmy23013 But Windows supports / too – MilkyWay90 – 2018-12-30T03:56:58.113

@MilkyWay90 Windows supports / in some places, but in cmd, /xxx is interpreted as an argument. – jimmy23013 – 2018-12-30T05:52:42.770

2

APL (40)

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

marinus

Posted 2014-05-21T20:28:28.333

Reputation: 30 224

39: X.Close⊣⎕DL⍴⍕'X'⎕WC'Form' 'Hello World' – Adám – 2016-06-28T19:48:54.790

2

Lua + LÖVE, 67 bytes

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

enter image description here

Seeker14491

Posted 2014-05-21T20:28:28.333

Reputation: 81

2

Perl 5, 47

Using Perl/Tk:

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

Matthias

Posted 2014-05-21T20:28:28.333

Reputation: 222

It seems that the Tk module is required. – A.L – 2014-05-22T18:03:00.617

2Yes, of course you need some GUI toolkit. I choose Tk because of tkinit(). – Matthias – 2014-05-23T05:57:02.750

I count 44 bytes. Are you counting the -MTk flag as well? – slebetman – 2014-05-23T08:12:39.057

@slebetman Yes I count that as 3 chars, I added the count to the post. – Matthias – 2014-05-23T08:15:44.877

@Matthias: maybe you should add it to the title language as Perl 5 + Tk. I tested it and was surprised to see that Perl 5 is not sufficient to run it. – A.L – 2014-05-23T08:59:48.910

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 – 2014-05-23T13:35:08.610

2

Perl on Windows (56)

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

chinese perl goth

Posted 2014-05-21T20:28:28.333

Reputation: 1 089

Use '-MWin32' to save four bytes – DarkHeart – 2017-06-06T08:49:52.990

2

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

segfaultd

Posted 2014-05-21T20:28:28.333

Reputation: 1 189

3Using 9 for Y position instead of 10 works for me. – user12205 – 2014-05-23T10:16:51.237

Just edited the code. Thanks! – segfaultd – 2014-05-23T14:48:13.587

3Just noticed you can use 3e3 instead of 3000 to save one more char – user12205 – 2014-05-23T17:11:53.280

2

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

draegtun

Posted 2014-05-21T20:28:28.333

Reputation: 1 592

2

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

Glenn Randers-Pehrson

Posted 2014-05-21T20:28:28.333

Reputation: 1 877

2

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 -

Bloke

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

unclemeat

Posted 2014-05-21T20:28:28.333

Reputation: 2 302

start "Hello world" You sir, are a genius. – user8397947 – 2016-07-13T01:26:45.937

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 – 2014-05-26T07:15:18.427

1I 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 – 2014-05-26T22:50:51.447

1

SmileBASIC, 23 bytes

DIALOG"hello world",,,3

enter image description here

12Me21

Posted 2014-05-21T20:28:28.333

Reputation: 6 110

1

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.

Adám

Posted 2014-05-21T20:28:28.333

Reputation: 37 779

1

Autohotkey, 22 Bytes

msgbox,,hello world,,3

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

msgbox

phil294

Posted 2014-05-21T20:28:28.333

Reputation: 169

1 year late lol – MilkyWay90 – 2018-12-30T04:05:24.213

1

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

Οurous

Posted 2014-05-21T20:28:28.333

Reputation: 7 916

1

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.

Justin

Posted 2014-05-21T20:28:28.333

Reputation: 19 757

Same idea, different module: turtle has less bytes. =D http://codegolf.stackexchange.com/a/28548/14506

– daviewales – 2014-05-24T13:12:52.197

1

Ruby [with Shoes] (44 chars)

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

osx app

Fabien Sa

Posted 2014-05-21T20:28:28.333

Reputation: 119

1

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

Bob

Posted 2014-05-21T20:28:28.333

Reputation: 844

1

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

Eduard Sukharev

Posted 2014-05-21T20:28:28.333

Reputation: 141

I don't know QML, but can you change true into 1 or 1>0? – user12205 – 2014-05-25T08:54:46.637

1@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 – Eduard Sukharev – 2014-05-25T15:50:20.573

1

PowerShell, 72 49

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

enter image description here

Thanks to @joey for continued golfing

iamkrillin

Posted 2014-05-21T20:28:28.333

Reputation: 280

saps -pa notepad "Hello World"|%{sleep 3;kill $_} would be quite a bit shorter. – Joey – 2014-05-25T09:25:32.740

1

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

user16402

Posted 2014-05-21T20:28:28.333

Reputation:

I'm curious if you could get this to work with rxvt to shave off a byte. – Zwei – 2016-07-13T03:52:21.463

1

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

DreamWarrior

Posted 2014-05-21T20:28:28.333

Reputation: 571

1

TCL, 52 bytes

label .l -text Hello\ World
pack .l
after 3000 exit

Kevin

Posted 2014-05-21T20:28:28.333

Reputation: 501

You can save bytes if you nest label into pack as: pack [label .l -text Hello\ World] – sergiol – 2017-11-02T23:45:45.010

1

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)

daviewales

Posted 2014-05-21T20:28:28.333

Reputation: 271

1

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)

Konrad Borowski

Posted 2014-05-21T20:28:28.333

Reputation: 11 185

1

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

Fozzedout

Posted 2014-05-21T20:28:28.333

Reputation: 121

1

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.

user8397947

Posted 2014-05-21T20:28:28.333

Reputation: 1 242

0

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

sergiol

Posted 2014-05-21T20:28:28.333

Reputation: 3 055

Unless you count the file name as part of your score, this violates this standard loophole.

– caird coinheringaahing – 2017-11-02T23:35:04.340

@cairdcoinheringaahing: fixed. I added the byte count of the file name without the .tcl part – sergiol – 2017-11-02T23:42:53.813

0

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

onionpsy

Posted 2014-05-21T20:28:28.333

Reputation: 201

0

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>

Origineil

Posted 2014-05-21T20:28:28.333

Reputation: 141

0

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

sansknwoledge

Posted 2014-05-21T20:28:28.333

Reputation: 101

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. – user12205 – 2014-05-23T10:24:30.667

@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 – sansknwoledge – 2014-05-23T12:41:16.380

0

Linux Shell, 54

echo "hello world">f;firefox f;sleep 3;killall firefox

John B

Posted 2014-05-21T20:28:28.333

Reputation: 109

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. – Glenn Randers-Pehrson – 2014-05-24T23:52:04.450

0

HTML/JavaScript (81)

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

elmoeleven

Posted 2014-05-21T20:28:28.333

Reputation: 9

0

Factor, 128 bytes

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

cat

Posted 2014-05-21T20:28:28.333

Reputation: 4 989