Python Forum
Tkinter Shell Terminal Or Shell Output
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tkinter Shell Terminal Or Shell Output
#3
Firstly thank you so much for taking the time to read my topic and your reply.

I am just starting with Python and I must admit I am struggling to adapt your code to my script.

I incorporated your code to the file (see below) but I can't figure out how to pass it on to each command for it to record onto the file.

p.s. I added a scrolleldtext to display the result once I have figured the above.

Again, thank you for your time and patience

import subprocess
from tkinter import *
from tkinter import messagebox
from tkinter import ttk
from tkinter import scrolledtext
import sys

window = Tk()

#Write terminal output to file
savefile = '/home/sweetth/PycharmProjects/pythonProject/stdout.txt'
hold_stdout = sys.stdout
sys.stdout = open(savefile, 'w')
sys.stdout = hold_stdout

#modify window
window.title("Server Commander")
window.geometry("600x350")

tab_control = ttk.Notebook(window)

#Creating tabs
tab1 = ttk.Frame(tab_control)
tab2 = ttk.Frame(tab_control)

#Modifying tabs
tab_control.add(tab1, text='Server')
tab_control.add(tab2, text='Computer')

#Creating button & actions
#Tab Server
def issue():
    subprocess.run('ssh [email protected] sudo systemctl start pyload', shell=True)
    messagebox.showinfo('Start PyLoad', 'PyLoad Started successfully!')
btn = Button(tab1, text="Start Pyload", command=issue, height=1, width=12)
btn.grid(column=1, row=5, sticky='news')

def issue():
    subprocess.run("ssh [email protected] sudo systemctl stop pyload", shell=True)
    messagebox.showinfo('Stop PyLoad', 'Pyload Stopped successfully!')
btn = Button(tab1, text="Stop PyLoad", command=issue, height=1, width=12)
btn.grid(column=2, row=5, sticky='news')

def issue():
    subprocess.run("ssh [email protected] python -m mnamer -bvr /mnt/hd/Download/", shell=True)
    messagebox.showinfo('Mnamer', 'Mnamer successfully!')
btn = Button(tab1, text="Mnamer", command=issue, height=1, width=12)
btn.grid(column=1, row=6, sticky='news')

def issue():
    subprocess.run("ssh [email protected] /usr/local/sbin/extractall.sh", shell=True)
    messagebox.showinfo('Extract Files', 'Extract Files successfully!')
btn = Button(tab1, text="Extract Files", command=issue, height=1, width=12)
btn.grid(column=1, row=7, sticky='news')

def issue():
    subprocess.run("ssh [email protected] rm /mnt/hd/Download/*.rar", shell=True)
    messagebox.showinfo('Remove Rar', 'Remove Rar successfully!')
btn = Button(tab1, text="Remove Rar", command=issue, height=1, width=12)
btn.grid(column=2, row=7, sticky='news')

def issue():
    subprocess.run("deepin-terminal -e ssh [email protected]", shell=True)
    messagebox.showinfo('SSH GoFlex', 'SSH GoFlex successfully!')
btn = Button(tab1, text="SSH GoFlex", command=issue, height=1, width=12)
btn.grid(column=1, row=8, sticky='news')

def issue():
    subprocess.run("deepin-terminal -e ssh [email protected]", shell=True)
    messagebox.showinfo('SSH Paco', 'SSH Paco successfully!')
btn = Button(tab1, text="SSH Paco", command=issue, height=1, width=12)
btn.grid(column=2, row=8, sticky='news')

def issue():
    subprocess.run("sudo -u sweetth mount /mnt/share && dde-file-manager /mnt/share/", shell=True)
    messagebox.showinfo('Mount GoFlex', 'Mount GoFlex successfully!')
btn = Button(tab1, text="Mount GoFlex", command=issue, height=1, width=12)
btn.grid(column=1, row=9, sticky='news')

def issue():
    subprocess.run("sudo umount /mnt/share", shell=True)
    messagebox.showinfo('Umount GoFlex', 'Umount GoFlex successfully!')
btn = Button(tab1, text="Umount GoFlex", command=issue, height=1, width=12)
btn.grid(column=2, row=9, sticky='news')

def issue():
    subprocess.run("ssh [email protected] sudo systemctl reboot", shell=True)
    messagebox.showinfo('Reboot NAS', 'Reboot NAS successfully!')
btn = Button(tab1, text="Reboot NAS", command=issue, height=1, width=12)
btn.grid(column=1, row=10, sticky='news')

def issue():
    subprocess.run("ssh [email protected] sudo systemctl poweroff", shell=True)
    messagebox.showinfo('Power Off NAS', 'Power Off NAS successfully!')
btn = Button(tab1, text="Power Off NAS", command=issue, height=1, width=12)
btn.grid(column=2, row=10, sticky='news')

text_area = scrolledtext.ScrolledText(tab1, width = 50 , height = 15, wrap="word")
text_area.grid(column=3, row=1, rowspan=12)

#Tab Computer
def issue():
    subprocess.run('sudo systemctl start pyload', shell=True)
    messagebox.showinfo('Start PyLoad', 'PyLoad Started successfully!')
btn = Button(tab2, text="Start PyLoad", command=issue, height=1, width=12)
btn.grid(column=1, row=1, sticky='news')

def issue():
    subprocess.run("sudo systemctl stop pyload", shell=True,)
    messagebox.showinfo('Stop PyLoad', 'Pyload Stopped successfully!')
btn = Button(tab2, text="Stop PyLoad", command=issue, height=1, width=12)
btn.grid(column=2, row=1, sticky='news')

text_area = scrolledtext.ScrolledText(tab2, width = 50 , height = 15, wrap="word")
text_area.grid(column=3, row=1, rowspan=12)

tab_control.pack(expand=1, fill='both')

#event loop
window.mainloop()
Reply


Messages In This Thread
RE: Tkinter Shell Terminal Or Shell Output - by sweetthdevil - Dec-01-2020, 06:46 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Tkinter | entry output. Sap2ch 1 2,073 Sep-25-2021, 12:38 AM
Last Post: Yoriz
  How to show terminal output in GUI Rubberduck 2 8,997 May-29-2021, 09:01 AM
Last Post: Rubberduck
  [Tkinter] acceleration of data output in treeview tkinter Vladimir1984 4 4,362 Nov-21-2020, 03:43 PM
Last Post: Vladimir1984
  Displaying output in GUI ( Tkinter) Zouloutamtam 7 18,852 Sep-29-2020, 02:08 PM
Last Post: Zouloutamtam
  [Tkinter] Logs and terminal in Tkinter Prezess 1 3,248 Jul-26-2020, 09:49 PM
Last Post: Larz60+
  How to display results from terminal window onto tkinter. buttercup 0 3,726 Jul-21-2020, 04:41 AM
Last Post: buttercup
  How to print out the wisget structure in shell menator01 0 1,672 Apr-26-2020, 04:20 AM
Last Post: menator01
  [GTK] Virtual python shell with Vte.Pty.spawn_async() jiri 2 3,441 Oct-20-2019, 12:16 PM
Last Post: Axel_Erfurt
  Active tkinter text output during loop dvanommen 2 10,920 Oct-18-2019, 02:23 PM
Last Post: dvanommen
  sQlite3 output to tkinter treeview - how do I set / increase width of the output? dewijones67 5 6,811 Jan-23-2019, 08:45 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020