Run shell command from GUI using Python Last Updated : 20 Oct, 2021 Comments Improve Suggest changes Like Article Like Report In this article, we are going to discuss how we can create a GUI window that will take Operating System commands as input and after executing them, displays the output in a pop-up window. Modules Required: PyAutoGui: It is a module in python which is used to automate the GUI and controls the mouse and keyboard. It is an external module, it can be installed in the system using the below command: Linux: pip3 install pyautogui Windows: pip install pyautogui OS: The OS module in Python provides functions for interacting with the operating system.This module comes under Python’s standard utility modules. It provides a portable way of using operating system dependent functionality. Approach:Import modules.Use the prompt() of pyautogui module to take input commandUse the system() of os module to execute the command.Finally, call the popen() of os module to generate a pop-up window and then using alert() of pyautogui module to display output.Implementation: Below program depicts how to create a window which takes operating system commands as input. Python3 # import required modules import os import pyautogui # prompts message on screen and takes the # input command in val variable val = pyautogui.prompt("Enter Shell Command") # executes the value of val variable os.system(val) Output: However, when commands are entered they are performed in the background. Below is a better version of the above previous python program in which on the execution of the given command, the output is displayed in a popup window. Python3 # import required modules import os import pyautogui # prompts message on screen and gets the command # value in val variable value = pyautogui.prompt("Enter Shell Command") # executes the command and returns # the output in stream variable stream = os.popen(value) # reads the output from stream variable out = stream.read() pyautogui.alert(out) Output: Comment More infoAdvertise with us Next Article Run shell command from GUI using Python A anurag702 Follow Improve Article Tags : Python Python-PyAutoGUI Practice Tags : python Similar Reads Run function from the command line In Python Python is a flexible programming language with a wide range of uses that one of Pythonâs most useful ones is its ability to execute functions from the command line. Especially this feature is very useful when it comes to automation and scripting etc. In this article, Iâll explain how to execute a Py 4 min read Executing Shell Commands with Python This article starts with a basic introduction to Python shell commands and why one should use them. It also describes the three primary ways to run Python shell commands.os.system()subprocess.run()subprocess.Popen() What is a shell in the os?In programming, the shell is a software interface for acce 4 min read 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 1 min read GUI Automation using Python In this article, we will explore how we can do GUI automation using Python. There are many modules that can do these things, but in this article, we will use a module named PyAutoGUI to perform GUI and desktop automation using python. We would explore two sections - How to automatically use the mou 12 min read Python: Weight Conversion GUI using Tkinter Prerequisites: Python GUI â tkinterPython offers multiple options for developing a GUI (Graphical User Interface). Out of all the GUI methods, Tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with Tkinter outputs the fastes 2 min read Run python using sublimeREPL SublimeREPL extends the capabilities of Sublime Text by allowing you to run Python scripts and interact with a Python REPL directly within the editor. With this setup, you can streamline your development workflow, test code snippets quickly, and see the results in real time without leaving Sublime T 2 min read Create First GUI Application using Python-Tkinter We are now stepping into making applications with graphical elements, we will learn how to make cool apps and focus more on its GUI(Graphical User Interface) using Tkinter.What is Tkinter?Tkinter is a Python Package for creating GUI applications. Python has a lot of GUI frameworks, but Tkinter is th 12 min read How to use CMD for Python in Windows 10? This article will guide you on how to run Python in CMD, execute scripts, and troubleshoot common issues. By mastering these CMD commands, you'll improve your coding efficiency and streamline your development process.Steps to Use CMD for Python in Windows 10Find the detailed steps to use CMD for Pyt 4 min read Useful IPython magic commands In this article, we will cover IPython Magic commands/functions and discuss various types of magic commands available. In this article we will be using Jupyter Notebook to execute the magic commands first, we look at what are Magic functions and why we use them, then different types of magic functio 6 min read How to Run a Python Script using Docker? Docker helps you to run your Python application very smoothly in different environments without worrying about underlying platforms. Once you build an image using dockerfile you can run that image wherever you want to run. Docker image will help you to package all the dependencies required for the a 8 min read Like