bonjour

par clic droit un popup arrive, je veux memoriser avec lastcluster et lastdata les nombres des 2 derniers champs

mais au prochain clic droit vous verrez que c'est toujours les valeurs initiales affichées
je comprends pas pourquoi

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
import sys
import Tkinter
 
root=Tkinter.Tk()
can=Tkinter.Canvas(root, width=300, height=300)
can.pack(fill="both", expand=1)
 
def main(argv=None):
    root.bind('<Button-3>', ask)
    root.geometry('+300+300')
    can.create_text(10,100,text="10")
    can.create_text(10,200,text="20")
    can.create_text(8,240,text="y")
    can.create_text(100,8,text="10")
    can.create_text(200,8,text="20")
    can.create_text(240,7,text="x")
 
    root.mainloop()
    return 0
 
 
fields = 'address', 'cluster', 'data'
lastcluster=64
lastdata=''
 
def fetch(variables):
#    for variable in variables:
#        print 'Input => "%i"' % variable.get()  
    try:
        address=int(variables[0].get())
        print 'ad => "%i"' % address
    except ValueError:
        address=None
        print 'ad => none' 
    try:
        cluster=int(variables[1].get())
        print 'cl => "0x%X"' % cluster
    except ValueError:
        cluster=None
        print 'cl => none' 
    try:
        i=int(variables[2].get())
        ii=str(i)
        data=[]
        tp=''
        for pos, ch in enumerate(ii):
            tp+=ch 
            if pos%2==1:
                data.append(int(tp))
                tp=''
        for j in range(len(data)):
            print ' "%i"' % data[j]
    except ValueError:
        data=[]
        print 'dat => none'   
#    _t.send(address, cluster, data)
 
def makeform(root, fields):
    form = Tkinter.Frame(root)                              
    left = Tkinter.Frame(form)                              
    rite = Tkinter.Frame(form)
    form.pack(fill=Tkinter.X) 
    left.pack(side=Tkinter.LEFT)
    rite.pack(side=Tkinter.RIGHT, expand=Tkinter.YES, fill=Tkinter.X)      
 
    variables=[]
    for i,field in enumerate(fields):
        lab = Tkinter.Label(left, width=7, text=field)     
        ent = Tkinter.Entry(rite)
        lab.pack(side=Tkinter.TOP)
        ent.pack(side=Tkinter.TOP, fill=Tkinter.X)
        var=Tkinter.StringVar()
        ent.config(textvariable=var)              
        if field== 'cluster':
            var.set(lastcluster)
        else:
            pass
        variables.append(var)
    return variables
 
 
def show(variables):
    popup.destroy()                
    fetch(variables)
    lastcluster=int(variables[1].get()) 
    print "show ",int(variables[1].get()), lastcluster           
 
def ask(event):
    global popup
    popup = Tkinter.Toplevel()
    popup.geometry('+%d+%d' %(root.winfo_rootx()+240, root.winfo_rooty()) )
    id=22
    vars = makeform(popup, fields)
    print "ask ",int(vars[1].get()), lastcluster
    Tkinter.Button(popup, text='OK', command=(lambda v=vars: show(v)) ).pack()
    popup.focus_set()
    popup.wait_window()
 
 
if __name__ == "__main__":
    sys.exit(main())
 
sys.exit(main())