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 :

NameError: global name 'entr2' is not defined


Sujet :

Tkinter Python

  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    85
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Avril 2008
    Messages : 85
    Par défaut "AttributeError: core" besoin de vous =)
    Résolu merci!

  2. #2
    Expert confirmé
    Avatar de tyrtamos
    Homme Profil pro
    Retraité
    Inscrit en
    Décembre 2007
    Messages
    4 486
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Retraité

    Informations forums :
    Inscription : Décembre 2007
    Messages : 4 486
    Billets dans le blog
    6
    Par défaut
    Bonjour,

    Effectivement, dans ta fonction config(), les variables créées sont des variables locales qui sont détruites à la fin de cette fonction... ce qui n'est probablement pas ce que tu voulais.

    Une des possibilités: abandonne le fichier config() et met son contenu en exécution au niveau global.

    Tyrtamos

  3. #3
    Membre confirmé
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    85
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Avril 2008
    Messages : 85
    Par défaut
    malhereusement se n'est pas possible (enfin je croix ) sa doit rester dedans pour que tout fonctionne

    programme complet :
    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
    #-*- coding:Utf-8 -*-
    from Tkinter import *
    import os
    fichier_config= open('config.ini', 'r')
    contenu = fichier_config.readlines()
    fichier_config.close ()
     
    try:
    	hostloc = str(contenu[1][0:len(contenu[1])-1]) # emplacement host
    	gameloc = str(contenu[2][0:len(contenu[2])-1]) #emplacement game
    	ipadress = str(contenu[3][0:len(contenu[3])-1]) #adresse ip
    	core = str(contenu[4][0:len(contenu[4])-1])#no version	
     
    except:
    	print "ERREUR! veuillez verifiez le fichier config.ini"
    def patcher(choix) :
            if choix ==1 :
                    host= open(hostloc, "a")
                    host.close()
                    host= open(hostloc, "w")
                    host.write('127.0.0.1 localhost\n')
                    host.write(ipadress +' l2authd.lineage2.com\n')
                    host.write(ipadress +' L2testauthd.lineage2.com\n')
                    host.write('216.107.250.194 nprotect.lineage2.com\n')
            elif choix ==2 :                
                    os.startfile(gameloc)
     
    def config() :
        fenetre2 = Tk()
        fenetre2.title('Modifiez...  ' + core)
        txt1 = Label(fenetre2, text = 'Jeu :').grid(row=0, sticky =E)
        txt2 = Label(fenetre2, text = 'Ip  :').grid(row=1, sticky =E)
        entr1 = Entry(fenetre2).grid(row =0, column =1)
        entr2 = Entry(fenetre2).grid(row= 1, column =1)
        bouton4 =Button(fenetre2, text= '  Ok  ', command =configadd).grid(row=2, column=1, sticky =E)
        fenetre2.mainloop()
        fenetre2.destroy()
    def configadd() :
    	global entr2
    	ipadress = str(entr2.get())
    	host= open(hostloc, "a")
            host.close()
            host= open(hostloc, "w")
            host.write('127.0.0.1 localhost\n')
            host.write(ipadress +' l2authd.lineage2.com\n')
    	host.write(ipadress +' L2testauthd.lineage2.com\n')
    	host.write('216.107.250.194 nprotect.lineage2.com\n')
     
    # affichage Tk
    fenetre = Tk()
    # image
    can1 = Canvas(fenetre, width =500, height =250, bg ='gray')
    photo = PhotoImage(file ='header.gif')
    item = can1.create_image(250, 125, image =photo)
    #image
    fenetre.title('l2-Luncher by Noquioz  ' + core)
    can1.pack()
    bouton1 = Button(fenetre, text='Patch', command = (lambda: patcher(1))).pack(side =BOTTOM)
    bouton2 = Button(fenetre, text='Play', command = (lambda: patcher(2))).pack(side =BOTTOM)
    bouton3 = Button(fenetre, text='Option', command =config).pack(side =BOTTOM)
    chaine = Label(fenetre)
    chaine.pack()
    fenetre.mainloop()
    fenetre.destroy()

  4. #4
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    6
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2007
    Messages : 6
    Par défaut utiliser class
    Pour éviter ces problèmes, il faut encapsuler ton programme dans une classe (j'ai longtemps galéré avant de le faire et plus après !!)
    exemple :
    class Application:
    def __init__(self):
    #ici les variables initiales de ton script

    self.entr2=3
    #puis tes fonctions (attention à ajouter self
    def config(self) :
    fenetre2 = Tk()
    fenetre2.title('Modifiez... ' + core)
    f

    def configadd(self) :
    def configadd(self) :
    self.ipadress = str(self.entr2.get())
    #puis tu instance la classe :

    import os
    import shutil

    f = Application() # instanciation de l'objet application

    maintenant si tu déclare une variable avec self. devant elle est valable dans toutes les fonction de la classe. Sans le self, elle n'est valable que dans la fonction ou elle est utilisée. Avec ça, plus de problème de poertée de variables !

  5. #5
    Membre émérite
    Homme Profil pro
    heu...
    Inscrit en
    Octobre 2007
    Messages
    648
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : heu...

    Informations forums :
    Inscription : Octobre 2007
    Messages : 648
    Par défaut
    Tout à fait, mais pour ce cas précis, si ne veut pas encapsuler ton prog dans une classe (ce qui serait vraiment dommage), au début ta procédure 'config', met ici aussi global entr2. Par contre comme je ne me sert jamais des globales, je ne sais plus si il faut que tu retires du coup global entr2 de ton autre procédure ou pas...essayes, tu verras bien

  6. #6
    Membre confirmé
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    85
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Avril 2008
    Messages : 85
    Par défaut
    Voila :
    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
    #-*- coding:Utf-8 -*-
     
    from Tkinter import *
     
    import os
     
    import shutil
     
    class programme :
     
        def __init__(self):
     
            self.hostloc = 0
     
            self.gameloc = 0
     
            self.ipadress = 0
     
            self.core = 0
     
            self.entr1 = 0
     
            self.entr2 = 0
     
            self.fichier_config = 0
     
            self.contenu = 0
     
            self.fichier_config= open("config.ini", "r")
     
            self.contenu = fichier_config.readlines()
     
            self.fichier_config.close ()
     
     
     
            try:
     
                self.hostloc = str(self.contenu[1][0:len(self.contenu[1])-1]) # emplacement host
     
                self.gameloc = str(self.contenu[2][0:len(self.contenu[2])-1]) #emplacement game
     
                self.ipadress = str(self.contenu[3][0:len(self.contenu[3])-1]) #adresse ip
     
                self.core = str(self.contenu[4][0:len(self.contenu[4])-1])#no version   
     
     
     
            except:
     
                print "ERREUR! veuillez verifiez le fichier config.ini"
     
                raw_input()
     
    def patcher(self, choix) :
     
            if choix ==1 :
     
                    host= open(self.hostloc, "a")
     
                    host.close()
     
                    host= open(self.hostloc, "w")
     
                    host.write('127.0.0.1 localhost\n')
     
                    host.write(self.ipadress +' l2authd.lineage2.com\n')
     
                    host.write(self.ipadress +' L2testauthd.lineage2.com\n')
     
                    host.write('216.107.250.194 nprotect.lineage2.com\n')
     
            elif choix ==2 :                
     
                    os.startfile(self.gameloc)
     
     
     
    def config(self) :
     
        fenetre2 = Tk()
     
        fenetre2.title('Modifiez...  ' + self.core)
     
        txt1 = Label(fenetre2, text = 'Jeu :').grid(row=0, sticky =E)
     
        txt2 = Label(fenetre2, text = 'Ip  :').grid(row=1, sticky =E)
     
        self.entr1 = Entry(fenetre2).grid(row =0, column =1)
     
        self.entr2 = Entry(fenetre2).grid(row= 1, column =1)
     
        bouton4 =Button(fenetre2, text= '  Ok  ', command =self.configadd).grid(row=2, column=1, sticky =E)
     
        fenetre2.mainloop()
     
        fenetre2.destroy()
     
    def configadd(self) :
     
        self.ipadress = str(self.entr2.get())
     
        host= open(self.hostloc, "a")
     
        host.close()
     
        host= open(self.hostloc, "w")
     
        host.write('127.0.0.1 localhost\n')
     
        host.write(self.ipadress +' l2authd.lineage2.com\n')
     
        host.write(self.ipadress +' L2testauthd.lineage2.com\n')
     
        host.write('216.107.250.194 nprotect.lineage2.com\n')
     
     
     
    # affichage Tk
     
    fenetre = Tk()
     
    # image
     
    can1 = Canvas(fenetre, width =500, height =250, bg ='gray')
     
    photo = PhotoImage(file ="header.gif")
     
    item = can1.create_image(250, 125, image =photo)
     
    #image
     
    def affichage(self) : 
        fenetre.title('l2-Luncher by Noquioz  ' + self.core)
        can1.pack()
     
        bouton1 = Button(fenetre, text='Patch', command = (lambda: self.patcher(1))).pack(side =BOTTOM)
     
        bouton2 = Button(fenetre, text='Play', command = (lambda: self.patcher(2))).pack(side =BOTTOM)
     
        bouton3 = Button(fenetre, text='Option', command =self.config).pack(side =BOTTOM)
     
        chaine = Label(fenetre)
     
        chaine.pack()
     
        fenetre.mainloop()
     
        fenetre.destroy()
    il ya rien qui apparait se qui me semble normal =P car faut que j'appelle affichage mais comment ?

  7. #7
    Membre confirmé
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    85
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Avril 2008
    Messages : 85
    Par défaut
    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
    #-*- coding:Utf-8 -*-
     
    from Tkinter import *
     
    import os
     
    import shutil
     
    class programme :
     
        def __init__(self):
     
            self.hostloc = 0
     
            self.gameloc = 0
     
            self.ipadress = 0
     
            self.core = 0
     
            self.entr1 = 0
     
            self.entr2 = 0
     
            self.fichier_config = 0
     
            self.contenu = 0
     
            self.fichier_config= open("config.ini", "r")
     
            self.contenu = fichier_config.readlines()
     
            self.fichier_config.close ()
     
     
     
            try:
     
                self.hostloc = str(self.contenu[1][0:len(self.contenu[1])-1]) # emplacement host
     
                self.gameloc = str(self.contenu[2][0:len(self.contenu[2])-1]) #emplacement game
     
                self.ipadress = str(self.contenu[3][0:len(self.contenu[3])-1]) #adresse ip
     
                self.core = str(self.contenu[4][0:len(self.contenu[4])-1])#no version   
     
     
     
            except:
     
                print "ERREUR! veuillez verifiez le fichier config.ini"
     
                raw_input()
     
    def patcher(self, choix) :
     
            if choix ==1 :
     
                    host= open(self.hostloc, "a")
     
                    host.close()
     
                    host= open(self.hostloc, "w")
     
                    host.write('127.0.0.1 localhost\n')
     
                    host.write(self.ipadress +' l2authd.lineage2.com\n')
     
                    host.write(self.ipadress +' L2testauthd.lineage2.com\n')
     
                    host.write('216.107.250.194 nprotect.lineage2.com\n')
     
            elif choix ==2 :                
     
                    os.startfile(self.gameloc)
     
     
     
    def config(self) :
     
        fenetre2 = Tk()
     
        fenetre2.title('Modifiez...  ' + self.core)
     
        txt1 = Label(fenetre2, text = 'Jeu :').grid(row=0, sticky =E)
     
        txt2 = Label(fenetre2, text = 'Ip  :').grid(row=1, sticky =E)
     
        self.entr1 = Entry(fenetre2).grid(row =0, column =1)
     
        self.entr2 = Entry(fenetre2).grid(row= 1, column =1)
     
        bouton4 =Button(fenetre2, text= '  Ok  ', command =self.configadd).grid(row=2, column=1, sticky =E)
     
        fenetre2.mainloop()
     
        fenetre2.destroy()
     
    def configadd(self) :
     
        self.ipadress = str(self.entr2.get())
     
        host= open(self.hostloc, "a")
     
        host.close()
     
        host= open(self.hostloc, "w")
     
        host.write('127.0.0.1 localhost\n')
     
        host.write(self.ipadress +' l2authd.lineage2.com\n')
     
        host.write(self.ipadress +' L2testauthd.lineage2.com\n')
     
        host.write('216.107.250.194 nprotect.lineage2.com\n')
     
     
    def affichage(self) :
        fenetre = Tk()
     
     
        can1 = Canvas(fenetre, width =500, height =250, bg ='gray')
        photo = PhotoImage(file ="header.gif")
        item = can1.create_image(250, 125, image =photo)
     
     
        fenetre.title('l2-Luncher by Noquioz  ' + self.core)
        can1.pack()
     
        bouton1 = Button(fenetre, text='Patch', command = (lambda: self.patcher(1))).pack(side =BOTTOM)
     
        bouton2 = Button(fenetre, text='Play', command = (lambda: self.patcher(2))).pack(side =BOTTOM)
     
        bouton3 = Button(fenetre, text='Option', command =self.config).pack(side =BOTTOM)
     
        chaine = Label(fenetre)
     
        chaine.pack()
     
        fenetre.mainloop()
     
        fenetre.destroy()
     
    h= affichage(fenetre)
    h.pack()
    bon maintenant :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    Traceback (most recent call last):
      File "C:\Users\Julien Moret\Desktop\luncher\luncher.py", line 144, in <module>
        h= affichage(fenetre)
      File "C:\Users\Julien Moret\Desktop\luncher\luncher.py", line 127, in affichage
        fenetre.title('l2-Luncher by Noquioz  ' + self.core)
      File "C:\Python25\lib\lib-tk\Tkinter.py", line 1721, in __getattr__
        return getattr(self.tk, attr)
    AttributeError: core

  8. #8
    Membre confirmé
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    85
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Avril 2008
    Messages : 85
    Par défaut
    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
    #-*- coding:Utf-8 -*-
     
    from Tkinter import *
     
    import os
     
    import shutil
     
    class programme :
     
        def __init__(self):
     
            self.hostloc = 0
     
            self.gameloc = 0
     
            self.ipadress = 0
     
            self.core = 0
     
            self.entr1 = 0
     
            self.entr2 = 0
     
            self.fichier_config = 0
     
            self.contenu = 0
     
            self.fichier_config= open("config.ini", "r")
     
            self.contenu = fichier_config.readlines()
     
            self.fichier_config.close ()
     
     
     
            try:
     
                self.hostloc = str(self.contenu[1][0:len(self.contenu[1])-1]) # emplacement host
     
                self.gameloc = str(self.contenu[2][0:len(self.contenu[2])-1]) #emplacement game
     
                self.ipadress = str(self.contenu[3][0:len(self.contenu[3])-1]) #adresse ip
     
                self.core = str(self.contenu[4][0:len(self.contenu[4])-1])#no version   
     
     
     
            except:
     
                print "ERREUR! veuillez verifiez le fichier config.ini"
     
                raw_input()
     
    def patcher(self, choix) :
     
            if choix ==1 :
     
                    host= open(self.hostloc, "a")
     
                    host.close()
     
                    host= open(self.hostloc, "w")
     
                    host.write('127.0.0.1 localhost\n')
     
                    host.write(self.ipadress +' l2authd.lineage2.com\n')
     
                    host.write(self.ipadress +' L2testauthd.lineage2.com\n')
     
                    host.write('216.107.250.194 nprotect.lineage2.com\n')
     
            elif choix ==2 :                
     
                    os.startfile(self.gameloc)
     
     
     
    def config(self) :
     
        fenetre2 = Tk()
     
        fenetre2.title('Modifiez...  ' + self.core)
     
        txt1 = Label(fenetre2, text = 'Jeu :').grid(row=0, sticky =E)
     
        txt2 = Label(fenetre2, text = 'Ip  :').grid(row=1, sticky =E)
     
        self.entr1 = Entry(fenetre2).grid(row =0, column =1)
     
        self.entr2 = Entry(fenetre2).grid(row= 1, column =1)
     
        bouton4 =Button(fenetre2, text= '  Ok  ', command =self.configadd).grid(row=2, column=1, sticky =E)
     
        fenetre2.mainloop()
     
        fenetre2.destroy()
     
    def configadd(self) :
     
        self.ipadress = str(self.entr2.get())
     
        host= open(self.hostloc, "a")
     
        host.close()
     
        host= open(self.hostloc, "w")
     
        host.write('127.0.0.1 localhost\n')
     
        host.write(self.ipadress +' l2authd.lineage2.com\n')
     
        host.write(self.ipadress +' L2testauthd.lineage2.com\n')
     
        host.write('216.107.250.194 nprotect.lineage2.com\n')
     
     
    def affichage() :
        fenetre = Tk()
     
     
        can1 = Canvas(fenetre, width =500, height =250, bg ='gray')
        photo = PhotoImage(file ="header.gif")
        item = can1.create_image(250, 125, image =photo)
     
     
        fenetre.title('l2-Luncher by Noquioz  ' + self.core)
        can1.pack()
     
        bouton1 = Button(fenetre, text='Patch', command = (lambda: self.patcher(1))).pack(side =BOTTOM)
     
        bouton2 = Button(fenetre, text='Play', command = (lambda: self.patcher(2))).pack(side =BOTTOM)
     
        bouton3 = Button(fenetre, text='Option', command =self.config).pack(side =BOTTOM)
     
        chaine = Label(fenetre)
     
        chaine.pack()
     
        fenetre.mainloop()
     
        fenetre.destroy()
     
    h=affichage()
    h.pack()
    la j'ai enlever self dans la dernière définition.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
        fenetre.title('l2-Luncher by Noquioz  ' + self.core)
    NameError: global name 'self' is not defined
    j'en conclu que c'est *** de self marche pas =(
    mais comment ?

  9. #9
    Membre émérite
    Homme Profil pro
    heu...
    Inscrit en
    Octobre 2007
    Messages
    648
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : heu...

    Informations forums :
    Inscription : Octobre 2007
    Messages : 648
    Par défaut
    Voici un lien qui te sera très utile

  10. #10
    Membre confirmé
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    85
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Avril 2008
    Messages : 85
    Par défaut
    Merci de ta réponse
    (j'ai déjà tout lu et je viens de relire)
    mais sa m'aide pas =(

  11. #11
    Membre confirmé
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    85
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Avril 2008
    Messages : 85
    Par défaut
    ZzZzZ
    sans classe
    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
    #-*- coding:Utf-8 -*-
    from Tkinter import *
    import os
    fichier_config= open('config.ini', 'r')
    contenu = fichier_config.readlines()
    fichier_config.close ()
     
    try:
        hostloc = str(contenu[1][0:len(contenu[1])-1]) # emplacement host
        gameloc = str(contenu[2][0:len(contenu[2])-1]) #emplacement game
        ipadress = str(contenu[3][0:len(contenu[3])-1]) #adresse ip
        core = str(contenu[4][0:len(contenu[4])-1])#no version	
     
    except:
    	print "ERREUR! veuillez verifiez le fichier config.ini"
    def patcher(choix) :
        if choix ==1 :
                host= open(hostloc, "a")
                host.close()
                host= open(hostloc, "w")
                host.write('127.0.0.1 localhost\n')
                host.write(ipadress +' l2authd.lineage2.com\n')
                host.write(ipadress +' L2testauthd.lineage2.com\n')
                host.write('216.107.250.194 nprotect.lineage2.com\n')
        elif choix ==2 :                
                os.startfile(gameloc)
     
    def config() :
        global entr2
        fenetre2 = Tk()
        fenetre2.title('Modifiez...  ' + core)
        txt1 = Label(fenetre2, text = 'Jeu :').grid(row=0, sticky =E)
        txt2 = Label(fenetre2, text = 'Ip  :').grid(row=1, sticky =E)
        entr1 = Entry(fenetre2).grid(row =0, column =1)
        entr2 = Entry(fenetre2).grid(row= 1, column =1)
        bouton4 =Button(fenetre2, text= '  Ok  ', command =configadd).grid(row=2, column=1, sticky =E)
        fenetre2.mainloop()
        fenetre2.destroy()
    def configadd() :
        ipadress = str(entr2.get())
        host= open(hostloc, "a")
        host.close()
        host= open(hostloc, "w")
        host.write('127.0.0.1 localhost\n')
        host.write(ipadress +' l2authd.lineage2.com\n')
        host.write(ipadress +' L2testauthd.lineage2.com\n')
        host.write('216.107.250.194 nprotect.lineage2.com\n')
     
    # affichage Tk
    fenetre = Tk()
    # image
    can1 = Canvas(fenetre, width =500, height =250, bg ='gray')
    photo = PhotoImage(file ='header.gif')
    item = can1.create_image(250, 125, image =photo)
    #image
    fenetre.title('l2-Luncher by Noquioz  ' + core)
    can1.pack()
    bouton1 = Button(fenetre, text='Patch', command = (lambda: patcher(1))).pack(side =BOTTOM)
    bouton2 = Button(fenetre, text='Play', command = (lambda: patcher(2))).pack(side =BOTTOM)
    bouton3 = Button(fenetre, text='Option', command =config).pack(side =BOTTOM)
    chaine = Label(fenetre)
    chaine.pack()
    fenetre.mainloop()
    fenetre.destroy()
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
        ipadress = str(entr2.get())
    AttributeError: 'NoneType' object has no attribute 'get'
    TT *déprime*
    je sais que vous savez =(

  12. #12
    Expert confirmé
    Avatar de tyrtamos
    Homme Profil pro
    Retraité
    Inscrit en
    Décembre 2007
    Messages
    4 486
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Retraité

    Informations forums :
    Inscription : Décembre 2007
    Messages : 4 486
    Billets dans le blog
    6
    Par défaut
    Bonjour,

    "global entr2" permet de dire à la fonction config qu'il faut chercher la variable "entr2" dans les variables globales, mais elle n'existe pas comme variable globale.

    => initialise entr2 comme variable globale comme je te l'ai suggéré.

    Tyrtamos

  13. #13
    Membre confirmé
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    85
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Avril 2008
    Messages : 85
    Par défaut
    Citation Envoyé par tyrtamos Voir le message
    => initialise entr2 comme variable globale comme je te l'ai suggéré.
    c'est à dire ?
    je dois l'enlever de config() (?) c'est pas possible, boutton oblige.

  14. #14
    Expert confirmé
    Avatar de tyrtamos
    Homme Profil pro
    Retraité
    Inscrit en
    Décembre 2007
    Messages
    4 486
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Retraité

    Informations forums :
    Inscription : Décembre 2007
    Messages : 4 486
    Billets dans le blog
    6
    Par défaut
    Non, tu fais quelque chose comme:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    ...
    entr2 = None
    ...
    def config() :
        global entr2
        ...
        entr2 = Entry(fenetre2).grid(row= 1, column =1)
        ...
    Ainsi, lors de la config, c'est bien le entr2 global qui sera pris, et sa valeur sera reconnue sans pb partout dans les autres fonctions, à condition de le dire avec global entr2.

    Ok?

    Tyrtamos

  15. #15
    Membre confirmé
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    85
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Avril 2008
    Messages : 85
    Par défaut
    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
    #-*- coding:Utf-8 -*-
    from Tkinter import *
    import os
    fichier_config= open('config.ini', 'r')
    contenu = fichier_config.readlines()
    fichier_config.close ()
    entr2 = None
     
    try:
        hostloc = str(contenu[1][0:len(contenu[1])-1]) # emplacement host
        gameloc = str(contenu[2][0:len(contenu[2])-1]) #emplacement game
        ipadress = str(contenu[3][0:len(contenu[3])-1]) #adresse ip
        core = str(contenu[4][0:len(contenu[4])-1])#no version	
     
    except:
    	print "ERREUR! veuillez verifiez le fichier config.ini"
    def patcher(choix) :
        if choix ==1 :
                host= open(hostloc, "a")
                host.close()
                host= open(hostloc, "w")
                host.write('127.0.0.1 localhost\n')
                host.write(ipadress +' l2authd.lineage2.com\n')
                host.write(ipadress +' L2testauthd.lineage2.com\n')
                host.write('216.107.250.194 nprotect.lineage2.com\n')
        elif choix ==2 :                
                os.startfile(gameloc)
     
    def config() :
        global entr2
        fenetre2 = Tk()
        fenetre2.title('Modifiez...  ' + core)
        txt1 = Label(fenetre2, text = 'Jeu :').grid(row=0, sticky =E)
        txt2 = Label(fenetre2, text = 'Ip  :').grid(row=1, sticky =E)
        entr1 = Entry(fenetre2).grid(row =0, column =1)
        entr2 = Entry(fenetre2).grid(row= 1, column =1)
        bouton4 =Button(fenetre2, text= '  Ok  ', command =configadd).grid(row=2, column=1, sticky =E)
        fenetre2.mainloop()
        fenetre2.destroy()
    def configadd() :
        ipadress = str(entr2.get())
        host= open(hostloc, "a")
        host.close()
        host= open(hostloc, "w")
        host.write('127.0.0.1 localhost\n')
        host.write(ipadress +' l2authd.lineage2.com\n')
        host.write(ipadress +' L2testauthd.lineage2.com\n')
        host.write('216.107.250.194 nprotect.lineage2.com\n')
     
    # affichage Tk
    fenetre = Tk()
    # image
    can1 = Canvas(fenetre, width =500, height =250, bg ='gray')
    photo = PhotoImage(file ='header.gif')
    item = can1.create_image(250, 125, image =photo)
    #image
    fenetre.title('l2-Luncher by Noquioz  ' + core)
    can1.pack()
    bouton1 = Button(fenetre, text='Patch', command = (lambda: patcher(1))).pack(side =BOTTOM)
    bouton2 = Button(fenetre, text='Play', command = (lambda: patcher(2))).pack(side =BOTTOM)
    bouton3 = Button(fenetre, text='Option', command =config).pack(side =BOTTOM)
    chaine = Label(fenetre)
    chaine.pack()
    fenetre.mainloop()
    fenetre.destroy()
    j'ai fait se que tu m'as dis mais c'est pareil.
    (le none est au debut)

  16. #16
    Expert confirmé
    Avatar de tyrtamos
    Homme Profil pro
    Retraité
    Inscrit en
    Décembre 2007
    Messages
    4 486
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Retraité

    Informations forums :
    Inscription : Décembre 2007
    Messages : 4 486
    Billets dans le blog
    6
    Par défaut
    Si je simplifie à l'extrême cette partie de code concernant entr2, ça donne:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    entr2=None
     
    def config():
        global entr2
        entr2=5
     
    config()
    print entr2
    Ce qui affiche, bien entendu "5": la fonction config() a bien fait son boulot.

    Tyrtamos

  17. #17
    Membre émérite
    Homme Profil pro
    heu...
    Inscrit en
    Octobre 2007
    Messages
    648
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : heu...

    Informations forums :
    Inscription : Octobre 2007
    Messages : 648
    Par défaut
    Je crois avoir piger, en fait c'est tout con ton problème : dans ta procédure configadd tu fais un appel a entry2, seulement l'ordi lui cherche entry2 en tant que variable locale, donc à l'intérieur de la procédure... donc, au début de la dite procédure (configadd), rajoute global entry2, tout simplement

    Sinon, la totalité de l'application encapsulée dans une classe donne à peu près ça :
    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
    from Tkinter import *
    import os
     
    class Appli:
        def __init__(self):
            self.fichier_config= open('config.ini', 'r')
            self.contenu = self.fichier_config.readlines()
            self.fichier_config.close ()
            self.entr2 = None
     
            try:
                self.hostloc = str(contenu[1][0:len(contenu[1])-1]) # emplacement host
                self.gameloc = str(contenu[2][0:len(contenu[2])-1]) #emplacement game
                self.ipadress = str(contenu[3][0:len(contenu[3])-1]) #adresse ip
                self.core = str(contenu[4][0:len(contenu[4])-1])#no version
     
            except:
            	print "ERREUR! veuillez verifiez le fichier config.ini"
            self.defwidget()
     
        def defwidget(self):
                # affichage Tk
                self.fenetre = Tk()
                # image
                self.can1 = Canvas(self.fenetre, width =500, height =250, bg ='gray')
                self.item = can1.create_image(250, 125, image =PhotoImage(file ='header.gif'))
                #image
                self.fenetre.title('l2-Luncher by Noquioz  ' + self.core)
                self.can1.pack()
                self.bouton1 = Button(self.fenetre, text='Patch', command = (lambda: self.patcher(1)))
                self.bouton1.pack(side =BOTTOM)
                self.bouton2 = Button(self.fenetre, text='Play', command = (lambda: self.patcher(2)))
                self.bouton2.pack(side =BOTTOM)
                self.bouton3 = Button(self.fenetre, text='Option', command =self.config)
                self.bouton3.pack(side =BOTTOM)
                self.chaine = Label(self.fenetre)
                self.chaine.pack()
     
        def patcher(self,choix) :
                if choix ==1 :
                        host= open(self.hostloc, "a")
                        host.close()
                        host= open(self.hostloc, "w")
                        host.write('127.0.0.1 localhost\n')
                        host.write(self.ipadress +' l2authd.lineage2.com\n')
                        host.write(self.ipadress +' L2testauthd.lineage2.com\n')
                        host.write('216.107.250.194 nprotect.lineage2.com\n')
                elif choix ==2 :
                        os.startfile(self.gameloc)
     
        def config(self) :
                self.fenetre2 = Toplevel()
                self.fenetre2.title('Modifiez...  ' + self.core)
                self.txt1 = Label(self.fenetre2, text = 'Jeu :')
                self.txt1.grid(row=0, sticky =E)
                self.txt2 = Label(self.fenetre2, text = 'Ip  :')
                self.txt2.grid(row=1, sticky =E)
                self.entr1 = Entry(self.fenetre2)
                self.entr1.grid(row =0, column =1)
                self.entr2 = Entry(self.fenetre2)
                self.entr2.grid(row= 1, column =1)
                self.bouton4 =Button(self.fenetre2, text= '  Ok  ', command =self.configadd)
                self.bouton4.grid(row=2, column=1, sticky =E)
     
        def configadd(self) :
                self.ipadress = str(self.entr2.get())
                host= open(self.hostloc, "a")
                host.close()
                host= open(self.hostloc, "w")
                host.write('127.0.0.1 localhost\n')
                host.write(self.ipadress +' l2authd.lineage2.com\n')
                host.write(self.ipadress +' L2testauthd.lineage2.com\n')
                host.write('216.107.250.194 nprotect.lineage2.com\n')
     
    #lancement
    a=Appli()
    a.fenetre.mainloop()

  18. #18
    Membre confirmé
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    85
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Avril 2008
    Messages : 85
    Par défaut
    sa fait déjà un moment, mais je cherche toujours...
    Voila j'ai mis en pièce jointe les fichiers
    je serai très reconnaissant a la personne qui arrive a faire fonctionner le menu option.
    Merci d'avance
    Fichiers attachés Fichiers attachés

  19. #19
    Membre confirmé
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    85
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Avril 2008
    Messages : 85
    Par défaut
    J'ai ma solution
    il faut tout simplement séparer les .grid
    entrer = entry()
    entrer.grid()

    voila c'était vraiment con. ^^

Discussions similaires

  1. NameError: global name 'thread' is not defined
    Par Balbuzard dans le forum Général Python
    Réponses: 6
    Dernier message: 15/07/2009, 06h52
  2. Réponses: 4
    Dernier message: 19/06/2009, 15h23
  3. références croisées objets NameError: global name is not defined
    Par loicmidy dans le forum Général Python
    Réponses: 2
    Dernier message: 13/06/2009, 15h41
  4. NameError: name 'nbBug' is not defined
    Par titi_lion dans le forum Général Python
    Réponses: 1
    Dernier message: 15/05/2009, 12h32
  5. NameError: name 'excel' is not defined
    Par billyrose dans le forum Général Python
    Réponses: 3
    Dernier message: 14/07/2008, 17h37

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