Create a desktop launcher (shortcut) to shutdown\restart Ubuntu.


New Member
Hi Folks, Cybermoron posted a thread on creating a nifty shutdown button on the Win 7
desktop to make shutdown\restart easier.
I posted that I use a similar method to shutdown\restart my Ubuntu installs using a simple
python script.

He suggested I share that here in the Linux section so here goes.

First I can't take credit for the script it was created by another individual over at the Ubuntu forums.

Below is the script text.

#!/usr/bin/env python

import os
import sys
import pygtk
import gtk

class power:
    def restart(self, event):
            command = "sudo shutdown -r now"
    def shutdown(self, event):
        command = "sudo shutdown -h now"
    def cancel(self, event):
        import sys
    def delete_event(self, widget, event, data=None):
            return False
    def __init__(self):
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.set_title("Power Options")
        self.window.connect("delete_event", self.delete_event)
        self.box1 = gtk.HBox(False, 0)
        self.button1 = gtk.Button("Restart")
        self.button1.connect("clicked", self.restart)
        self.box1.pack_start(self.button1, True, True, 0)
        self.button2 = gtk.Button("Shutdown")
        self.button2.connect("clicked", self.shutdown)
        self.box1.pack_start(self.button2, True, True, 0)
        self.button3 = gtk.Button("Cancel")
        self.button3.connect("clicked", self.cancel)
        self.box1.pack_start(self.button3, True, True, 0)
def main():
if __name__=="__main__":
    pwr = power()
The first thing to do is to right click an empty area of your desktop and choose "create document>empty file".
Open the resulting empty file in gedit or another suitable text editor and copy\paste all the text from the script above into the empty document file.
Save and name the file power_options.

Next right click the newly created power_options file and select properties>permissions and make sure that "allow executing file as a program" is selected.
All other permissions should be correct if you created the file on your desktop.

Close the properties dialog box and move the file to your /home/<your user name> folder
where <your user name> is your user name without the <> symbols.

The two commands below should be done in terminal as user.
Do not do as root.

You can do this from the terminal by typing
cd Desktop
and clicking enter.
The D in desktop must be uppercase.


cp power_options /home/<your user name>
again your own user name without the <> symbols and click enter.

Alternatively if you have a desktop shortcut to your /home directory just cut and copy the file to it.

Now that the file is in your /home directory we will now make a desktop launcher (shortcut) to it.

Right click a blank area of your desktop and choose "Create Launcher..".
In the resulting dialog box make sure "application" is selected in the type: dropdown menu.
In the name: field name then launcher anything you want, I chose Quit.
In the command: field type python /home/<your user name>/power_options, again using your actual user name without <> where it says <your user name>.

In the upper left corner of the launcher dialog box is a generic icon.
Click this icon to change the icon to a more acceptable one from the list.
If you have an icon of your own then place it in your /home directory and navigate to it using the browse feature.

attached below is the icon I use.


If you want to use this icon just click on the attachment thumbnail and right click the resulting image and choose "save image as..." and save it to your /home folder.
It will be saved as a .png.
Navigate to that icon file as instructed above to use it as your icon.

Click ok when done and you should have a brand new launcher on your desktop with
the icon of your choice.

Right click the new launcher and choose properties>permissions and make sure "allow executing file as a program" is selected, close the properties box and you launcher is ready for use.

When clicked your new shutdown button will open a small dialog box where you can select shutdown, restart or cancel.

I've tested this on all versions of Ubuntu from Dapper Drake (Ubuntu 6.04 LTS) to the latest Lucid Lynx (Ubuntu 10.04 LTS) and the launcher works very well.
I haven't tested it the KDE versions (Kubuntu) but it should work just as well.

It should work on other debian based Linux distros but I haven't tested it.

Have fun with your new Desktop shutdown button.

Last edited:
This website is not affiliated, owned, or endorsed by Microsoft Corporation. It is a member of the Microsoft Partner Program.