-1

I am making an application through python tkinter; I am not able to understand how I can run a shell script with it.

My use case is , when I press a button it will invoke a shell script and display its output in GUI.

  • 1
    Does this answer your question? [Run process with realtime output to a Tkinter GUI](https://stackoverflow.com/questions/30410421/run-process-with-realtime-output-to-a-tkinter-gui) – Shivam Roy Jun 28 '21 at 18:29

1 Answers1

0

You're looking for the subprocess module:

https://docs.python.org/3/library/subprocess.html

An example:

subprocess.run(["ls"]). # run ls
output = subprocess.check_output(["ls"]) # grab the output of ls
alex.weavers
  • 28
  • 1
  • 5
  • It is throwing below error when trying to display the output in label -------------------- AttributeError: 'NoneType' object has no attribute 'set' – Aman Sinha Jun 28 '21 at 18:37
  • This will most likely not help OP because if the script runs for too long it can make the window unresponsive. – TheLizzard Jun 28 '21 at 18:53
  • @AmanSinha Look at [this](https://stackoverflow.com/questions/1101750/tkinter-attributeerror-nonetype-object-has-no-attribute-attribute-name). – TheLizzard Jun 28 '21 at 18:53
  • @TheLizzard Thanks it resolve my issue. Also the size of the frame in tkinter is not increasing my shell script output is not displayed correctly ; Is there a way to increase the size of that frame – Aman Sinha Jun 28 '21 at 19:24
  • @AmanSinha The frame should resize itself to fit the widgets inside. I think something else is going on but without seeing your code there is no way of me giving you an answer. Please ask a new stackoverflow question if you need to. – TheLizzard Jun 28 '21 at 19:34
  • This is the code for frame self.frame1 = Frame(masterwindow, width=500, height=250, bg="#00B388",borderwidth = 5) self.frame1.pack(padx=10, pady=250) – Aman Sinha Jun 28 '21 at 19:42