Inspired by The Most Useless Machine Ever.

Write the shortest program that does the following:

  • create a graphical window, then immediately close the window and exit the program.
  • do this in some visually apparent manner. Like the "arm" that pushes the switch in the machine, the program must use some visual method in the GUI to close itself.
  • this visual method must be what causes the program to close; you cannot just show it as something on the side (though there may be other things off to the side)


  • The program does not have to be visible long enough for the visible activity to be seen by a human as long as the activity is the cause of the closing.
  • The window must be a GUI (must display a graphical window that contains the visible exit method).
  • The visual method needs to be something the user could do if it wasn't done automatically. Explain what needs to be changed in the code for the user to be able to do this (Thanks to Iszi).
  • The program must close if there is no interference from the user, but if the user interferes, then it does not need to close automatically.
  • Please include an explanation of what it is that causes the program to close.

Example: a window containing a button which is programmatically clicked, running a short snippet of code that closes the program.

  • 2
    \$\begingroup\$ I'd suggest that, for programs not visible enough to be seen by a human, answers should include mention of what should be changed in the code (adding/increasing timer values, etc. - but not fundamentally changing its functionality) in order to demonstrate to a human that it actually does something visual. \$\endgroup\$
    – Iszi
    Dec 9, 2013 at 16:37
  • 1
    \$\begingroup\$ Should this be code golf or a popularity contest? \$\endgroup\$
    – Kevin
    Mar 30, 2014 at 22:56
  • 1
    \$\begingroup\$ I've changed my TI-BASIC answer to a compiled version that is shorter than my other answer (which is currently accepted). I'd appreciate it if you could change that :) \$\endgroup\$
    – Timtech
    Apr 2, 2014 at 13:30
  • 1
    \$\begingroup\$ I'm curious why this question is being DVd and VTCd. For one, this has an objective winning criterion; it's a [code-golf]. I can understand that this isn't the best question, but why is it being VTCd? \$\endgroup\$
    – Justin
    Oct 19, 2017 at 18:19

9 Answers 9


Ruby with Shoes, 110

exit if u<0
p.text=' '*u+?<}}

Makes a little arrow that pushes a "Close" button. (Pushing the close button manually also closes the window.)



Windows Batch, 4 bytes

Save the following program to a .bat file in your user folder (C:\Users\username):


When executed from the Start, Run prompt, a new window opens, types the command Exit and executes it.

  • 1
    \$\begingroup\$ "The window must be a GUI (must display a graphical window that contains the visible exit method)." - it's arguable if your window contains the visible exit method, I'd say it doesn't. \$\endgroup\$
    – gronostaj
    Mar 31, 2014 at 11:35
  • 4
    \$\begingroup\$ @gronostaj It has an X in the top-right corner. \$\endgroup\$
    – Seiyria
    Mar 31, 2014 at 18:51
  • 1
    \$\begingroup\$ Ah, I see - you're exploiting the rules. There is a visible method to exit and user can do the same thing program does, but those are two different methods to terminate it. That's clever, +1. \$\endgroup\$
    – gronostaj
    Mar 31, 2014 at 19:41
  • \$\begingroup\$ Creating a .bat with only a space character: 1 byte? \$\endgroup\$
    – SEarle1986
    Mar 4, 2020 at 17:05
  • \$\begingroup\$ @SEarle1986, the space character wouldn't cause the program to exit. It would exit because it reached the end of the batch file. Exit will cause the window to close before the batch file completes. \$\endgroup\$ Mar 5, 2020 at 3:20

TI-Basic, 3 bytes


hex: 31 3E DF


DispGraph Displays the graph (a graphical window)

:1 Simulates a press of 1 (by storing 1 to Ans at the last step of a program), which takes the calculator back to the home screen. A user could do the same thing.

  • 3
    \$\begingroup\$ GTB is kind of stupid considering that the symbols for each command are stored a 2-byte values. \$\endgroup\$
    – TheDoctor
    Mar 30, 2014 at 14:40
  • \$\begingroup\$ Concurred, I (from inspection using CalcSys) would count as 6(perhaps 4, not sure if all OSs use single-byte tokens for : and 1). Filesystem overhead and tables are obviously not included in the count. \$\endgroup\$
    – nanofarad
    Apr 2, 2014 at 10:22
  • 2
    \$\begingroup\$ What do you mean by compiled? TI-BASIC is interpreted. \$\endgroup\$
    – Jakob
    Oct 19, 2017 at 3:43
  • \$\begingroup\$ @Jakob Back then I was more confused about how TI-Basic worked. What I should have said is the source is 3 1-byte tokens. Let me fix this answer \$\endgroup\$
    – Timtech
    Oct 19, 2017 at 12:29
  • \$\begingroup\$ @Jakob There we go. I think back then we were scoring TI-Basic programs by ascii byte count rather than tokens \$\endgroup\$
    – Timtech
    Oct 19, 2017 at 12:31

JavaScript: 133 117

(You need to allow popups in your web browser for this to work)



Source: http://jsfiddle.net/gt2t8/2/

  • \$\begingroup\$ Why does it resize? \$\endgroup\$
    – Justin
    Dec 8, 2013 at 3:05
  • \$\begingroup\$ @Quincunx do this in some visually apparent manner. Like the "arm" that pushes the switch in the machine, the program must use some visual method in the GUI to close itself. \$\endgroup\$ Dec 8, 2013 at 3:07
  • 1
    \$\begingroup\$ reduced to 117 chars: (function(){w=window.open(),d=999,i=setInterval(function(){w.resizeTo(d-=9,d);if(d<0)clearInterval(i),w.close()})})() \$\endgroup\$
    – Griffin
    Dec 8, 2013 at 4:20
  • \$\begingroup\$ @Griffin thanks! Updated with your suggestions \$\endgroup\$ Dec 8, 2013 at 4:46
  • 1
    \$\begingroup\$ One that I can run without leaving the page. Awesome. \$\endgroup\$
    – Seiyria
    Mar 31, 2014 at 18:51

Golf-Basic 84, 5 4


Display the graph, simluate a press of 1, closing the graph and returning home.

  • \$\begingroup\$ Does this do the same as your other answer? \$\endgroup\$
    – Justin
    Dec 12, 2013 at 7:58
  • \$\begingroup\$ @Quincunx Yes, it does. \$\endgroup\$
    – Timtech
    Dec 12, 2013 at 15:42

x86 / Win32 assembly (337 310 271 bytes)

.model flat
option casemap:none
include kernel32.inc
include windows.inc
include user32.inc
i textequ <invoke>
s:i CreateThread,0,0,$+46,0,0,0
i MessageBox,0,$,$,0
i ExitProcess,0
i Sleep,999
i FindWindow,0,$
i PostMessage,eax,256,13,0

Assembles with MASM32 (ml /c /coff /Gz /I<include path> test.asm / link /SUBSYSTEM:WINDOWS /LIBPATH:<library path> test.obj kernel32.lib user32.lib).

It creates a MessageBox with an "OK" button, and a thread that simulates a carriage return press from the user after 999 ms.

The $ is substituted with the address of the beginning of the code section by the assembler/linker. The first instruction is a push byte 0 (implicitly, since it's generated by the invoke), which is encoded as 6A 00, which equals the null-terminated string "j". I take advantage of this when calling MessageBox and FindWindow.

  • \$\begingroup\$ Is the assembly 271 bytes, or is that the size of the machine code? \$\endgroup\$
    – 12Me21
    Oct 19, 2017 at 14:00

Bash with X Window System, 10 chars

xterm -e :

Open an xterm window, run the bash no-op :, after which the xterm window closes.

If you want to see the useless window for a second, you can change the : to sleep 1:

xterm -e sleep 1

Tcl/Tk, 131

grid [button .b -command exit]
event generate .b <Button-1> -warp 1 -x 5 -y 5
event generate .b <ButtonRelease-1> -warp 1 -x 5 -y 5

Tcl/Tk, 136

grid [button .b -command exit]
event generate .b <ButtonPress-1> -warp 1 -x 5 -y 5
event generate .b <ButtonRelease-1> -warp 1 -x 5 -y 5

It needs to be ran on an interactive shell, line by line and user can not move the mouse between.

  1. Application starts

enter image description here

  1. Button whose behaviour is to close the app is added to the app window

enter image description here

  1. Generate an event that presses down the mouse on the button — Altough the cursor is not visible in the screenshot it is over the button; it is visible the buttonhas been pressed because it now sunken in, and before it was embossed out.

enter image description here

  1. Finally generate an event that releases the mouse button up.

    a. Image before really sending it (before pressing Enter) enter image description here

    b. After Enter the interactive shell and the app windows just disappeared. enter image description here

Note to tcl'ers: Tried to do the same directly on the window's X Close button using:

event generate . <ButtonPress-1> -warp 1 -x 175 -y -10
event generate . <ButtonRelease-1> -warp 1 -x 175 -y -10

but I was not successful.


Bash - echo (50 bytes)

Not golfed, 54 bytes:

s=sleep;echo -n \>\\;$s 1;echo -ne "\b\b >/";$s 1;echo

Golfed, 50 bytes

I can't exactly display the golf version here because the backspace characters actually backspace. For the golf version, change both of the "^H" to single backspace (^H) characters:

s=sleep;echo -n \>\\;$s 1;echo -n ^H^H \>/;$s 1;echo


  • The activity is visible for 2 seconds.

  • It doesn't use a window manager or anything of that sort, but I count the ASCII art as a "gui". If you are running the command in a terminal window, which is now the usual case, the activity is displayed in that window. It does not open up a new window.

  • The user can close the program sooner than the automatic close by hitting "CTRL-C" within 2 seconds of starting the program. Users who are more comfortable using their GUI can put their cursor on the little "X" in the corner of the terminal window, quickly, and "click" it.

  • The program closes after 2 seconds if there is no interference from the user. The user can only cause it to close sooner.

  • What causes the program to close is the completion of the final "echo".


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