Python 3 PyAutoGUI Tutorial to Run Terminal & Shell Commands From GUI Desktop App & Print the Result
163 views
Jun 3, 2025
Get the full source code of application here:
View Video Transcript
0:00
uh hello guys uh welcome to this video
0:02
so in this video I will show you how to
0:05
execute the terminal and shell commands
0:07
inside a python uh graphical user
0:10
interface kind of an application so
0:13
graphical user kind of application is
0:15
that application when where you can
0:17
actually see some widgets on the screen
0:20
let me show you a very simple example so
0:23
we have this application right here
0:25
which I built using pi auto this is a
0:28
free open-source library so the
0:31
interface will look something like this
0:32
it will ask you to enter any sort of
0:35
command here inside the input field so
0:37
here through the keyboard you can
0:39
actually write the name of the command
0:42
and then there are two buttons out there
0:44
either you can click okay or cancel so
0:47
this is a very easy kind of an
0:50
interface through which you can execute
0:52
commands so let's suppose I you can
0:55
execute any sort of command here uh so
0:57
let's suppose I want to print out the
0:59
version of python so simply I type here
1:01
python d- version so if as I click okay
1:05
here it will actually print out the
1:08
result of this command in the
1:11
uh guey as well so if I just click okay
1:13
here you will see it will print out the
1:15
version of python which is python
1:18
310.5 so essentially what it is doing it
1:21
is executing this uh command here in the
1:23
background and whatever is the result
1:26
right here that you see right here it is
1:28
printing directly in the graphical user
1:31
interface so I will show you this
1:33
library here which lets you do this so
1:36
first of all you just need to install
1:38
this uh pi auto GUI
1:42
library so this is essentially this
1:45
package here so this is just used for
1:48
creating the interface of the
1:50
application so pip install pi autogy you
1:54
can use any sort of framework it's not
1:57
restricted that you only use this
1:58
framework but this lets it's uh this
2:02
library makes it very much easy to
2:05
create the interface
2:07
so now the thing is that just create a
2:10
simple app py file and then import the
2:14
necessary packages so import operating
2:16
system and then we need to import pi
2:18
autogy package after that we simply
2:22
construct the input field where we will
2:25
allow the user to directly type the
2:28
command so it contains this function
2:30
here which is prompt which you can
2:34
execute and here you can simply say
2:37
enter shell
2:40
command and whatever the user writes it
2:44
so we simply execute this command by
2:46
using this function p open of operating
2:50
system and passing it the
2:52
value and then we display this whatever
2:55
is the output of the command we display
2:57
this using this
3:00
stream object and we read this and then
3:04
we display this so pi autogy and it
3:07
contains this alert function and we
3:09
display this so you can see only 10
3:12
lines of code is required for
3:14
this so we simply first of all require
3:17
the necessary packages then we construct
3:20
the input field by using the prompt
3:22
function and then we execute this
3:24
command by the operating system pop
3:27
method and then we read the output here
3:29
by using stream read and lastly we
3:32
display this on the screen by using the
3:34
alert method so if I just execute this
3:37
now you will see that
3:39
uh it will have this input
3:44
field so it will it constructed this
3:47
interface by using very small amount of
3:49
code here so we have this input field we
3:52
have these two buttons so if I let's
3:54
suppose just write a command here which
4:00
again let's suppose this time I want to
4:03
print out the version of
4:07
ffmppg so click on okay so it will print
4:10
out the result of this command in this
4:13
alert window so this is a very simple
4:16
application you can execute commands
4:19
terminal commands inside a GUI kind of
4:23
interface and print the result as well
4:25
so thank you very much for watching this
4:28
video and also check out my website
4:30
freemediattools.com
4:32
uh which contains thousands of tools
#Intelligent Personal Assistants
#Programming
#Scripting Languages