codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
#!/usr/bin/python3 # coding: utf-8 import time import shlex import tkinter from subprocess import Popen, PIPE def Ausfuehren(): if running.get() == True: print("Error: only one running command and once allowed!") status_label.configure(text="Error: another command is active!", fg="red") return command = option_choice.get() if eingabefeld.get() is not None: command = command + " " + eingabefeld.get() print("Befehl wird ausgefuehrt: %s" % command) running.set(True) status_label.configure(text="gestartet", fg="green") if run_command(command) != 0: status_label.configure(text="Fehler!", fg="red") else: status_label.configure(text="Beendet: "+str(option_choice.get()), fg="green") running.set(False) def Beenden(): print("Befehl wird beendet ...") status_label.configure(text="Beendet", fg="green") running.set(False) def run_command(command): process = Popen(shlex.split(command), stdout=PIPE, stderr=PIPE, bufsize=1) for output in iter(process.stdout.readline, b''): Log.insert(tkinter.END, (output)) print(output,) rc = process.poll() process.stdout.close() process.wait() print("\nDone") return rc # TKinter Main Window window = tkinter.Tk() window.geometry("500x500+10+10") status_label = tkinter.Label(master=window) status_label.configure(text=" ", fg="red") status_label.grid(row=0, column=0) start_button = tkinter.Button(master=window, bg="#229", fg="white", text="Run", command=Ausfuehren) stop_button = tkinter.Button(master=window, bg="#229", fg="white", text="Stop", command=Beenden) exit_button = tkinter.Button(master=window, bg="#229", fg="white", text="X", command=window.destroy) running = tkinter.BooleanVar() running.set(False) choices = ['apt-get update', 'apt-get upgrade', 'apt-get install', 'ls -la'] option_choice = tkinter.StringVar(window) options = tkinter.OptionMenu(window, option_choice, *choices) options.grid(row=1, column=0) eingabefeld = tkinter.Entry(master=window, width=20) eingabefeld.grid(row=1, column=3) start_button.grid(row=1, column=1) stop_button.grid(row=1, column=2) exit_button.grid(row=0, column=4) ScrollLog = tkinter.Scrollbar(window) Log = tkinter.Text(master=window, height=30, width=60) Log.grid(row=2, column=0, columnspan=5) ScrollLog.grid(row=2, column=5) ScrollLog.configure(command=Log.yview) Log.configure(yscrollcommand=ScrollLog.set) try: window.mainloop() except (KeyboardInterrupt, SystemExit): print("Schliesse Programm.")
Private
[
?
]
Run code
Submit