IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Tkinter Python Discussion :

modifier fenetre ouverte


Sujet :

Tkinter Python

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    306
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Mai 2008
    Messages : 306
    Par défaut modifier fenetre ouverte
    Bonjour,

    Comme l'indique le titre j'ai une fenêtre ouverte et j'ai besoin de la modifier (remplacer bouton et texte)
    J'ai ceci qui fonctionne sous ubuntu mais sur seven au moment de changer l'apparence, le script ne répond plus fichu microsof

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    racine=Tkinter.Tk()
    texte=Tkinter.Label(racine, text="Matricule", fg="black")
    bouton=Tkinter.Button(racine, text="OK", command=lambda: save(valsaisir.get(),racine,saisie))
    boutonESC=Tkinter.Button(racine, text="Fermer", command=racine.quit())
    valsaisir=Tkinter.StringVar() #variable to get value
    saisie=Tkinter.Entry(textvariable=valsaisir, width=30)
    cpt=0
    def MyTimer:
        cpt = int(cpt)+1
        if(cpt > 2):
            #racine.withdraw()
            isOpen = False
            showroot(1)
            #cpt = 0
            print "connecte"
        else:
            print now.strftime("%d/%m/%YT%H:%M:%S")
            #fen_matricule(racine)
            showroot(0)
            isOpen = True
     
        threading.Timer(tempo, MyTimer, [cpt,isOpen,tempo]).start()
     
    def showroot(param):
        if param == 0:
            texte.config(text='Matricule')
            bouton.pack(side=Tkinter.BOTTOM)
            boutonESC.pack_forget()
        else:
            texte.config(text='Le serveur répond de nouveau')
            bouton.pack_forget()
            boutonESC.pack(side=Tkinter.BOTTOM)
            saisie.pack_forget()
        racine.deiconify()
     
    def hideme():
        racine.withdraw()
        MyTimer(cpt,isOpen,float(time))
     
    hideme()
    racine.mainloop()
    Merci de votre aide

  2. #2
    Membre éclairé
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    306
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Mai 2008
    Messages : 306
    Par défaut
    Personne n'a une idée de pourquoi ça ne fonctionne pas sous windows et bien sous linux?

    merci

  3. #3
    Membre Expert Avatar de PauseKawa
    Homme Profil pro
    Technicien Help Desk, maintenance, réseau, système et +
    Inscrit en
    Juin 2006
    Messages
    2 725
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Technicien Help Desk, maintenance, réseau, système et +
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2006
    Messages : 2 725
    Par défaut
    Bonsoir,

    Et bien comme il manque une grosse partie du code (celui présenté n'étant pas fonctionnel) : non, pas d'idée.

    @+

  4. #4
    Membre éclairé
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    306
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Mai 2008
    Messages : 306
    Par défaut
    Voilà un code plus complet et donc sous windows, au moment où je dois changer l'apparence de la fenêtre.
    la fenêtre ne répond plus et donc mon thread s'arrête.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    #!/usr/bin/python
    # -*-coding:Utf-8 -* 
    import os,sys
    import ftplib as ftp
    import sched
    import time
    import datetime
    import threading
    import subprocess
    import Tkinter
    import re
     
    #répertoire courant du fichier
    dir_path = os.path.abspath(os.path.dirname(sys.argv[0]))
    racine=Tkinter.Tk()
     
     
    txtHr=Tkinter.Label(racine, text="", fg="black")
    texte=Tkinter.Label(racine, text="Entrez votre n° d'identification", fg="black")
    txtInfoServ=Tkinter.Label(racine, text="Serveur actif", fg="black")
    txtIP=Tkinter.Label(racine, text=ip, fg="black")
    bouton=Tkinter.Button(racine, text="Pointer", command=lambda: save(valsaisir.get(),racine,saisie))
    boutonESC=Tkinter.Button(racine, text="Fermer", command=racine.quit())
    valsaisir=Tkinter.StringVar() #variable to get value
    saisie=Tkinter.Entry(textvariable=valsaisir, width=30)
     
     
    isDown = False
    isOpen = False
    cpt = 0
    def MyTimer(cpt,isOpen,tempo = float(time)):
     
     
        if(cpt > 2):
            #racine.withdraw()
            isOpen = False
            showroot(1)
            #cpt = 0
            print "connecte"
        else:
            if(isOpen == False or isOpen == 'False'):
                print now.strftime("%d/%m/%YT%H:%M:%S")
                #fen_matricule(racine)
                showroot(0)
                isOpen = True
     
     
        threading.Timer(tempo, MyTimer, [cpt,isOpen,tempo]).start()
     
     
    def showroot(param):
        now = datetime.datetime.now() 
        if param == 0:
            txtInfoServ.config(text="Serveur inactif")
            bouton.configure(state='normal',background='red',command=lambda: save(valsaisir.get(),racine,saisie))
            saisie.configure(state='normal')
            txtHr.config(text=now.strftime("%H:%M:%S"))
            #boutonESC.pack_forget()
        else:
            txtInfoServ.config(text="Serveur actif")
            bouton.configure(state='disabled',background='green',command=racine.widthdraw())
            saisie.configure(state='disabled')
            txtHr.config(text=now.strftime("%H:%M:%S"))
     
        racine.deiconify()
     
     
    #def fen_matricule(racine):
    txtHr.pack(side=Tkinter.TOP)
    texte.pack(side=Tkinter.TOP)
    saisie.pack()
    #boutonESC.pack(side=Tkinter.BOTTOM)
    txtIP.pack(side=Tkinter.BOTTOM)
    txtInfoServ.pack(side=Tkinter.BOTTOM)
    bouton.pack(side=Tkinter.BOTTOM)
    #boutonESC.pack_forget()
    hideme()
    racine.configure(width=260,height=150)
    racine.mainloop()
    #MyTimer(isOpen,float(time))
    #show window
    #racine.wm_deiconify()
    Merci

  5. #5
    Membre Expert Avatar de PauseKawa
    Homme Profil pro
    Technicien Help Desk, maintenance, réseau, système et +
    Inscrit en
    Juin 2006
    Messages
    2 725
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Technicien Help Desk, maintenance, réseau, système et +
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2006
    Messages : 2 725
    Par défaut
    Re,

    Désolé bender86 mais ce code n'as aussi aucune chance de se lancer.
    Exemples:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    txtIP=Tkinter.Label(racine, text=ip, fg="black")
    ip n'est pas défini.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    def MyTimer(cpt,isOpen,tempo = float(time)):
    idem pour time. Ou plutôt si par l'import time mais bon ceci float(time) n'est pas utilisable sur un module.
    Soit vous donnez le code qui 'fonctionne' sous Ubuntu
    J'ai ceci qui fonctionne sous ubuntu
    Soit vous cherchez tout seul. Et je pense à la vue du code présenté que vous allez y passer un moment.

    A vous de voir. Perso je vous ai déjà présenter du code fonctionnel mais vous n'en tenez pas compte (et principalement de mes remarques*).
    Je ne vais donc pas refaire l'erreur ici.

    @+

    *) Et je ne suis pas, de très très loin, le meilleur sur le forum.

  6. #6
    Expert éminent
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 741
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Architecte technique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2008
    Messages : 21 741
    Par défaut
    Salut,

    Ce code ne marche pas sous Windows.
    Ca plante sur des lignes telles que:
    txtIP=Tkinter.Label(racine, text=ip, fg="black") ::: ip n'est pas défini
    def MyTimer(cpt,isOpen,tempo = float(time))::: pas très Python.

    Pour le reste, regardez les entrées qui parlent de threads et de Tkinter dans le "forum", elles indiquent toutes qu'appeler les méthodes d'un widget "directement" depuis un thread est tellement plein de surprise que ce n'est pas indiqué, supporté, recommandé -- Just don't do that!

    ... Mais vous pouvez le faire en postant l'appel via les points d'entrées de l'event loop

    Exemple:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
        if(cpt > 2):
            #racine.withdraw()
            isOpen = False
    #        showroot(1)
            racine.after_idle(showroot, 1)
            #cpt = 0
            print "connecte"
        else:
            if(isOpen == False or isOpen == 'False'):
                print now.strftime("%d/%m/%YT%H:%M:%S")
                #fen_matricule(racine)
    #            showroot(0)
                racine.after_idle(showroot, 0)
                isOpen = True
    Si le but du threads n'est que d'avoir un "timer", vous pouvez aussi le réaliser avec .after ( delay_ms, callback=None, *args )
    Bon courage
    - W
    PS: Grilled par PauseKawa
    Architectures post-modernes.
    Python sur DVP c'est aussi des FAQs, des cours et tutoriels

  7. #7
    Membre Expert Avatar de PauseKawa
    Homme Profil pro
    Technicien Help Desk, maintenance, réseau, système et +
    Inscrit en
    Juin 2006
    Messages
    2 725
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Technicien Help Desk, maintenance, réseau, système et +
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2006
    Messages : 2 725
    Par défaut
    Citation Envoyé par wiztricks Voir le message
    Si le but du threads n'est que d'avoir un "timer", vous pouvez aussi le réaliser avec .after ( delay_ms, callback=None, *args )
    Bon courage
    - W
    PS: Grilled par PauseKawa
    Niet : Je lui en ai déjà fais un exemple, il y as pas mal de temps (enfin... 30/07/2011). Il n'en tiens pas compte.

  8. #8
    Membre éclairé
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    306
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Mai 2008
    Messages : 306
    Par défaut
    Voilà ce qui fonctionne sous ubuntu et qui sous windows ne répond plus au moment où il faut modifier l'interface.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    #!/usr/bin/python
    # -*-coding:Utf-8 -* 
    import os,sys
    import ftplib as ftp
    import sched
    import time
    import datetime
    import threading
    import subprocess
    import Tkinter
    import re
     
    #répertoire courant du fichier
    dir_path = os.path.abspath(os.path.dirname(sys.argv[0]))
    racine=Tkinter.Tk()
     
     
    #sys.path[0]
    if sys.platform == "linux2":
        separateur = "/"
    elif sys.platform == "win32":
        separateur = "\\"
     
     
    ip="195.5.84.280"
     
     
    txtHr=Tkinter.Label(racine, text="", fg="black")
    texte=Tkinter.Label(racine, text="Entrez votre n° d'identification", fg="black")
    txtInfoServ=Tkinter.Label(racine, text="Serveur actif", fg="black")
    txtIP=Tkinter.Label(racine, text=ip, fg="black")
    bouton=Tkinter.Button(racine, text="Pointer", command=racine.withdraw)
    boutonESC=Tkinter.Button(racine, text="Fermer", command=racine.quit())
    valsaisir=Tkinter.StringVar() #variable to get value
    saisie=Tkinter.Entry(textvariable=valsaisir, width=30)
     
    isDown = False
    isOpen = False
    cpt = 0
    def MyTimer(cpt,isOpen,tempo):
     
        #si linux   
        if sys.platform == "linux2":
            lPing = subprocess.Popen(["ping","-c", "1 ", ip ],  
    					    stdout = subprocess.PIPE, 
    					    stderr = subprocess.PIPE) 
        elif sys.platform == "win32":
            lPing = subprocess.Popen(["ping","-n", "1 ", ip ],  
    					    stdout = subprocess.PIPE, 
    					    stderr = subprocess.PIPE) 
     
        sLigne, erreur = lPing.communicate()
        print sLigne
        transmis = 0
        received = 0
        loss = 100
        time = 0
        cpt = int(cpt) + 1
        #si linux   
        if sys.platform == "linux2":
            info_reg = info_reg = re.search(r'(\d+) packets transmitted',sLigne,re.M)
            if info_reg:
                transmis = int(info_reg.group(1))
            info_reg = info_reg = re.search(r'(\d+) received',sLigne,re.M)
            if info_reg:
                received = int(info_reg.group(1))
            info_reg = info_reg = re.search(r'(\d+)% packet loss',sLigne,re.M)
            if info_reg:
                loss = int(info_reg.group(1))
                if loss == 100:
                    loss = 1
            info_reg = info_reg = re.search(r'time (\d+)ms',sLigne,re.M)
            if info_reg:
                time = int(info_reg.group(1))
            #info_reg = info_reg = re.search(r'(\d+) packets transmitted, (\d+) received, (.+)% packet loss, time (\d+)ms',sLigne,re.M)
        elif sys.platform == "win32":
            info_reg = info_reg = re.search(r'envoy\Ds = (\d+)',sLigne,re.M)
            if info_reg:
                transmis = int(info_reg.group(1))
            info_reg = info_reg = re.search(r're\Dus = (\d+)',sLigne,re.M)
            if info_reg:
                received = int(info_reg.group(1))
            info_reg = info_reg = re.search(r'perte (\d+)%',sLigne,re.M)
            if info_reg:
                loss = int(info_reg.group(1))
            info_reg = info_reg = re.search(r'Moyenne = (\d+)ms',sLigne,re.M)
            if info_reg:
                time = int(info_reg.group(1))
            #info_reg = info_reg = re.search(r'Paquets : envoyés = (\d+), reçus = (\d+), perdus = (\d+) perte (.+)%',sLigne,re.M)
     
        now = datetime.datetime.now()
        #si l'expression régulière a donné un résultat
        if transmis > 0:
            """transmis = int(info_reg.group(1))
            received = int(info_reg.group(2))
            loss = int(info_reg.group(3))
            time = int(info_reg.group(4))"""
            isDown = False
            if received == 0:
                isDown = True
     
    	    #si le serveur répond après avoir été down et qu'il y a un fichier à uploader alors upload
    	    #recupere les parametres du fichier 
            if isDown == False or isDown == 'False':
                #Ferme la fenêtre pour encoder les pointages locales
                if isOpen == True or isOpen == 'True':
                    #close window
                    #racine.destroy()
                    showroot(1)
     
     
                isOpen = False
            else:
                if(cpt > 2):
                    #racine.withdraw()
                    isOpen = False
                    hideme()
                    #showroot(1)
                    #cpt = 0
                    print "connecte"
                else:
                    if(received == 0 and (isOpen == False or isOpen == 'False')):
                        print now.strftime("%d/%m/%YT%H:%M:%S")
                        #fen_matricule(racine)
                        showroot(0)
                        isOpen = True
     
        else:
            print cpt
            if(cpt > 2):
                isOpen = False
                showroot(1)
                print "connecte"
            if(received == 0 and (isOpen == False or isOpen == 'False')):
                print now.strftime("%d/%m/%YT%H:%M:%S")
                #fen_matricule(racine)
                showroot(0)
                isOpen = True
     
     
        threading.Timer(2.0, MyTimer, [cpt,isOpen,2.0]).start()
     
     
    def showroot(param):
        now = datetime.datetime.now() 
        if param == 0:
            txtInfoServ.config(text="Serveur inactif")
            bouton.configure(state='normal',background='red',command=lambda: save(valsaisir.get(),racine,saisie))
            saisie.configure(state='normal')
            txtHr.config(text=now.strftime("%H:%M:%S"))
            #boutonESC.pack_forget()
        else:
            txtInfoServ.config(text="Serveur actif")
            bouton.configure(state='disabled',background='green',command=racine.withdraw)
            saisie.configure(state='disabled')
            txtHr.config(text=now.strftime("%H:%M:%S"))
     
        racine.deiconify()
     
    def hideme():
        racine.withdraw()
        MyTimer(cpt,isOpen,2.0)
     
    #def fen_matricule(racine):
    txtHr.pack(side=Tkinter.TOP)
    texte.pack(side=Tkinter.TOP)
    saisie.pack()
    #boutonESC.pack(side=Tkinter.BOTTOM)
    txtIP.pack(side=Tkinter.BOTTOM)
    txtInfoServ.pack(side=Tkinter.BOTTOM)
    bouton.pack(side=Tkinter.BOTTOM)
    #boutonESC.pack_forget()
    hideme()
    racine.configure(width=260,height=150)
    racine.mainloop()
    #MyTimer(isOpen,float(time))
    #show window
    #racine.wm_deiconify()
    Merci de votre aide mais je débute

    PS: j'ai bien entendu essayer d'appliquer au mieux ce que tu m'as montré

  9. #9
    Expert confirmé
    Avatar de fred1599
    Homme Profil pro
    Lead Dev Python
    Inscrit en
    Juillet 2006
    Messages
    4 062
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Meurthe et Moselle (Lorraine)

    Informations professionnelles :
    Activité : Lead Dev Python
    Secteur : Arts - Culture

    Informations forums :
    Inscription : Juillet 2006
    Messages : 4 062
    Par défaut
    sans compter la fonction save(), hideme(), le non respect des conventions (voir PEP8)

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    isOpen = False
    cpt = 0
    def MyTimer(cpt,isOpen,tempo):


    Des lignes sont bien trop longues, etc...

    Un conseil, refaites un code avec le module tkinter seul, en simulant ce que vous recherchez, le code sera concis.

    Testez et vérifiez que l'erreur recommence sur windows et non sur linux.

    Montrez votre code qui déconne, on pourra vous aider

  10. #10
    Membre éclairé
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    306
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Mai 2008
    Messages : 306
    Par défaut
    Voilà j'ai fait un simple test qui fonctionne sous ubuntu en modifiant bien l'apparence et sous windows ça bloque.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    # -*- coding: utf-8 -*-
     
    #
     
    #
     
    #
     
    import subprocess
     
    try:
     
        import Tkinter as Tk
     
        import threading
     
    except:
     
        import tkinter as Tk
     
        import threading
     
     
     
     
     
    host = '192.168.1.1'
     
    isOpen = False
     
    root = Tk.Tk()
     
    root.title('Information connexion')
     
    txtInfoServ=Tk.Label(root, text="Connexion perdue avec l'hote %s" % host, fg='red')
     
    btWait=Tk.Button(root, text='Attendre')
     
    btQuit=Tk.Button(root, text='Quitter', command=root.quit)
     
     
     
     
     
     
     
    def showroot(param):
     
        if param == 1:
     
            txtInfoServ.config(text="Connexion retrouvée", fg='green')
     
            btQuit.configure(state='normal',background='green', command=root.destroy)
     
            btWait.configure(state='normal',background='green', command=root.withdraw)
     
        else:
     
            txtInfoServ.config(text="Connexion perdue avec l'hôte %s" % host, fg='red')
     
            btWait.configure(state='normal',background='red', command=root.withdraw)
     
            btQuit.configure(state='normal',background='red', command=root.destroy)
     
        root.deiconify()
     
     
     
     
     
    def pingme(cpt,isOpen):
     
        cpt = int(cpt) + 1
     
        print cpt
     
        if cpt > 11:
     
            showroot(1)
     
        else:
     
            if isOpen == False:
     
                showroot(0)
     
                isOpen = True
     
     
     
        threading.Timer(2.0, pingme, [cpt,isOpen]).start()
     
     
     
     
    def hideme():
     
        root.withdraw()
     
        cpt = 0
     
        isOpen = False
     
        pingme(cpt,isOpen)
     
     
     
     
     
    txtInfoServ.pack(padx=5, pady=5)
     
    btWait.pack(side=Tk.LEFT, padx=5, pady=5)
     
    btQuit.pack(side=Tk.RIGHT, padx=5, pady=5)
     
    hideme()
     
    root.mainloop()
    Merci de votre aide

  11. #11
    Expert éminent
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 741
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Architecte technique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2008
    Messages : 21 741
    Par défaut
    Salut,

    La pédagogie passe par la répétition: ne pas appeler directement une méthode Tk depuis un thread.
    i.e. remplacer au moins les appels a showroot(n) par root.after_idle(showroot, n)

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    def pingme(cpt,isOpen):
        cpt = int(cpt) + 1
        print cpt
        if cpt > 5:
            root.after_idle(showroot, 1)
        else:
            if isOpen == False:
                root.after_idle(showroot, 0)
                isOpen = True
        threading.Timer(1.0, pingme, [cpt,isOpen]).start()
    Si vous donnez l'impression de ne pas essayer de comprendre l'aide qu'on essaie de vous apporter vous aller vite en décourager plus d'un...
    - W
    Architectures post-modernes.
    Python sur DVP c'est aussi des FAQs, des cours et tutoriels

  12. #12
    Membre éclairé
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    306
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Mai 2008
    Messages : 306
    Par défaut
    Et donc je peux remplacer le threading.timer par un root.after(2000,pingme) ce qui permettra de boucler comme le timer?
    Et ainsi le showroot modifiera bien la fenetre?

    Merci et deso de ma lenteur de comprehension

  13. #13
    Expert éminent
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 741
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Architecte technique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2008
    Messages : 21 741
    Par défaut
    Salut,

    Citation Envoyé par bender86 Voir le message
    Et donc je peux remplacer le threading.timer par un root.after(2000,pingme) ce qui permettra de boucler comme le timer?
    Et ainsi le showroot modifiera bien la fenetre?
    Techniquement oui.
    Dans la pratique, vous devriez pouvoir tester "votre" ping indépendamment de l'interface graphique et réciproquement. Et le ping c'est quand même une action qui se termine par "il a répondu" ou "timeout"... => il y a un timer avec le "ping".
    Et si on veut séparer action et interface graphique, on (enfin "je") évitera le root.after dans ce cas.
    - W
    Architectures post-modernes.
    Python sur DVP c'est aussi des FAQs, des cours et tutoriels

  14. #14
    Membre Expert Avatar de PauseKawa
    Homme Profil pro
    Technicien Help Desk, maintenance, réseau, système et +
    Inscrit en
    Juin 2006
    Messages
    2 725
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Technicien Help Desk, maintenance, réseau, système et +
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2006
    Messages : 2 725
    Par défaut
    Bonsoir,

    Pourquoi ne pas partir simple.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    #!/usr/bin/env python
    # -*- coding: UTF-8 -*-
    #
    #
    import subprocess
    import sys
    try:
        import Tkinter as Tk
    except:
        import tkinter as Tk
     
    host = '192.168.1.1'
    if sys.platform == "win32":
        countstr = '-n'
        # '100% packet loss' a corriger pour Windows (Pas de Windows dispo)
        lostprc = '100% packet loss'
    else: # C'est -c sous mac ?
        countstr = '-c'
        lostprc = '100% packet loss'
     
    def pingme():
        root.withdraw()
        ping = subprocess.Popen(['ping', countstr, '1', host], stdout=subprocess.PIPE)
        stdo = ping.communicate()
        if lostprc in str(stdo):
            root.deiconify()
        else:
            root.after(2000, pingme)
     
    root = Tk.Tk()
    root.title('Information connexion')
    Tk.Label(root,
             text="Connexion perdue avec l'hote %s"% host, fg='red').pack(padx=5,
                                                                          pady=5)
    Tk.Button(root,
              text='Attendre', command=pingme).pack(side=Tk.LEFT,
                                                    padx=5, pady=5)
    Tk.Button(root, text='Quitter', command=root.quit).pack(side=Tk.RIGHT,
                                                            padx=5, pady=5)
    pingme()
    root.mainloop()
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    #!/usr/bin/env python
    # -*- coding: UTF-8 -*-
    #
    #
    import subprocess
    import sys
    try:
        import Tkinter as Tk
    except:
        import tkinter as Tk
     
    host = '192.168.1.1'
    if sys.platform == "win32":
        countstr = '-n'
        # '100% packet loss' a corriger pour Windows (Pas de Windows dispo)
        lostprc = '100% packet loss'
    else: # C'est -c sous mac ?
        countstr = '-c'
        lostprc = '100% packet loss'
     
    def pingme():
        root.withdraw()
        ping = subprocess.Popen(['ping', countstr, '1', host], stdout=subprocess.PIPE)
        stdo = ping.communicate()
        if lostprc in str(stdo):
            root.deiconify()
        else:
            root.after(2000, pingme)
     
    root = Tk.Tk()
    root.title('Information connexion')
    Tk.Label(root, text="Connexion perdue avec l'hote %s"% host, fg='red').pack(padx=5, pady=5)
    Tk.Button(root, text='Attendre', command=pingme).pack(side=Tk.LEFT, padx=5, pady=5)
    Tk.Button(root, text='Quitter', command=root.quit).pack(side=Tk.RIGHT, padx=5, pady=5)
    pingme()
    root.mainloop()
    A tester sous Windows bien sur.

    @+

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [WD55]Connaitre les fenetres ouvertes
    Par tunizar dans le forum WinDev
    Réponses: 15
    Dernier message: 01/03/2007, 14h16
  2. Réponses: 17
    Dernier message: 07/02/2007, 14h39
  3. Minimiser toutes les fenetres ouvertes
    Par Tragnee dans le forum WinDev
    Réponses: 5
    Dernier message: 18/01/2007, 13h13
  4. limiter le nombres de fenetres ouvertes de IE
    Par Essilife dans le forum IE
    Réponses: 5
    Dernier message: 31/03/2006, 14h29
  5. Maintenir la fenetre ouverte (dev c++ 4.9.9.2)
    Par lcstriker dans le forum Dev-C++
    Réponses: 4
    Dernier message: 03/11/2005, 15h56

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo