Partage
  • Partager sur Facebook
  • Partager sur Twitter

Tkinter recevoir#envoyez des commandes linux

import os, sys, Tkinter, csv

Sujet résolu
    24 mars 2015 à 7:01:06

    Bonjour à vous,

    J'ai un problème concernant le retour des commande. J'aimerais créer mon petit programme avec interface graphique ( Tkinter ), pour des commandes linux.

    Je suis capable d'envoyer, mais pas de recevoir.

    os.system('command')

    os.popen

    J'ai créer une fenêtre qui y ressemble.

    #!/usr/bin/python
    # -*- coding: utf-8 -*
    
    import os, sys
    import csv
    import Tkinter as tk
    from Tkinter import BOTH, END, LEFT
    
    ##########################
    ######## Centrez #########
    ##########################
    class CenterWindows():
        def __init__(self, original, w, h):
            """ COnstructor"""
            self.original = original
            self.w = w
            self.h = h
            ws = self.original.winfo_screenwidth()
            hs = self.original.winfo_screenheight()
            # calculate position x, y
            x = (ws/2) - (w/2)
            y = (hs/2) - (h/2)
            self.original.geometry('%dx%d+%d+%d' % (w, h, x, y))
         
    ##########################
    ########## Main ##########
    ##########################
    class Fen_Principale_tk(tk.Tk) : # Creation de la fenetre principale
        """Tout se qui concerne la base du programme """
        def __init__(self,parent):
            tk.Tk.__init__(self,parent)
            self.parent = parent
            self.initialize()
            self.HakunaMatata()
            Centrez = CenterWindows(self, 400, 500) # Class Centrez Fenetre
            self.BoutonP()
    
            
        def initialize(self):
            """ Afficher un titre  """
            label_titreP = tk.Label(self, text='NlTest')
            label_titreP.pack()
    
        def HakunaMatata(self):
            t = tk.Text(self)
            t.pack()
            def go():
                p = os.popen("find . -name '*.py'", 'r')
                for l in p.xreadlines():
                    t.insert(END, '%s\n' % l.rstrip())
                    t.see(END)
                    t.update_idletasks()
    
            tk.Button(self, text='Recherche', command=go).pack()
    
        def BoutonP(self) :
            """ Boutons Principales """
            buttonQ = tk.Button(self, text ='QuitteR', command =self.quit)
            buttonQ.pack()
            
    if __name__ == "__main__":
        app = Fen_Principale_tk(None)
        app.title('NLTest')
        app.mainloop()
        app.destroy()
    

    J'aimerais simplement dans un champ de texte, envoyez une commande. Recevoir l'information du shell..

    S'il y a une erreur, afficher un Tail -f ( du système et non pas de python )

    Si tout est correct, il affiche ce que le shell linux affichera ( comme une Boite de Commande Linux )

    Il existe peut-être déjà une solution, Je ne sais probablement juste pas quoi écrire sur google. haha

    Merci de m'aider et passer une belle journée.

    • Partager sur Facebook
    • Partager sur Twitter

    Tkinter recevoir#envoyez des commandes linux

    × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
    × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
    • Editeur
    • Markdown