Bonjour,
j'ai récupérer le code suivant sur le net auquel j'ai apporté de petites modifications :
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
#!/usr/bin/env python
#coding=utf-8
 
import Tkinter
 
answers = None
 
class simpleapp_tk(Tkinter.Tk):
    def __init__(self):
        Tkinter.Tk.__init__(self, None)
        self.__initialize()
 
    def __initialize(self):
        self.grid()
 
# Static text
        self.labelVariable = Tkinter.StringVar()
 
        label = Tkinter.Label(self,
                              textvariable = self.labelVariable)
        label.grid(row=0,
                   column=0,
                   sticky='EW')
 
        self.labelVariable.set(u"a = ")
 
# Entry here the user can give its value
        self.entryVariable = Tkinter.StringVar()
 
        self.entry = Tkinter.Entry(self,
                                   textvariable = self.entryVariable)
        self.entry.grid(row = 0,
                        column = 1,
                        sticky='EW')
#    self.entry.bind("<Return>", self.OnPressEnter)
 
        self.entryVariable.set(u"Votre valeur")
 
# One Button to say that everythong is ok
 
        button = Tkinter.Button(self,
                                text = u"OK",
                                command = self.OnButtonClick)
        button.grid(row = 0,
                    column = 2)
 
        self.grid_columnconfigure(0,
                                  weight=1)
        self.resizable(True,
                       False)
        self.update()
        self.geometry(self.geometry())
        self.entry.focus_set()
        self.entry.selection_range(0, Tkinter.END)
 
    def OnButtonClick(self):
        global answers
        answers = self.entryVariable.get()
 
# Tout fermer maintenant.
 
 
if __name__ == "__main__":
    app = simpleapp_tk()
    app.title('my application')
    a = app.mainloop()
 
    if answers != None:
        print answers
Il y a deux choses que je n'arrive pas à faire :
  1. Fermer mon application au moment indiquer en commentaire.
  2. Récupérer le contenu de "l'entrée" sans passer par une variable globale.


Toute info. est bienvenue.

PS : l'idée de mon code est de fournir un alternative visuelle au input de la console.