Wednesday, November 19, 2025
HomeLanguagesGUI to Shutdown, Restart and Logout from the PC using Python

GUI to Shutdown, Restart and Logout from the PC using Python

In this article, we are going to write a python script to shut down or Restart or Logout your system and bind it with GUI Application. 

The OS module in Python provides functions for interacting with the operating system. OS is an inbuilt library python.

Syntax :

For shutdown your system : os.system(“shutdown /s /t 1”)

For restart your system : os.system(“shutdown /r /t 1”)

For Logout your system : os.system(“shutdown -l”)

Implementation GUI Application using Tkinter:

Python3




# import modules
from tkinter import *
import os
 
 
# user define function
def shutdown():
    return os.system("shutdown /s /t 1")
 
def restart():
    return os.system("shutdown /r /t 1")
 
def logout():
    return os.system("shutdown -l")
 
 
# tkinter object
master = Tk()
 
# background set to grey
master.configure(bg='light grey')
 
# creating a button using the widget
# Buttons that will call the submit function
Button(master, text="Shutdown", command=shutdown).grid(row=0)
Button(master, text="Restart", command=restart).grid(row=1)
Button(master, text="Log out", command=logout).grid(row=2)
 
mainloop()


Output:

Note: Please ensure that you save and close all the programs before running this code on the IDLE, as this program will immediately shutdown and restart your computer.

RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32404 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6775 POSTS0 COMMENTS
Nicole Veronica
11924 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11994 POSTS0 COMMENTS
Shaida Kate Naidoo
6903 POSTS0 COMMENTS
Ted Musemwa
7159 POSTS0 COMMENTS
Thapelo Manthata
6859 POSTS0 COMMENTS
Umr Jansen
6846 POSTS0 COMMENTS