| 12
 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
 
 | from tkinter import *
 
 
class Detection_touche(object):
 
    def __init__(self, boss):
        self.fen = boss
        self.flag = 'abc'
        self.fen.bind("<KeyPress>", self.Appui)
        self.fen.bind("<KeyRelease>", self.Relache)
 
 
    #L'appui prolongé sur une touche du clavier appelle plusieurs fois l'évenement
    #La variable "flag" permet d'intercepter le 1er évenement
    def Appui(self, event):
 
        flagTest = event.keysym
 
        if self.flag != flagTest:
            self.flag = flagTest
            print ("appui    : touche=",event.keysym)
        return(self.flag)
        return 'break'
 
 
    def Relache(self, event):
 
        print ("relache  : touche=",event.keysym)
        print('')
 
        self.flag = 'abc'
 
 
    def Resultat(self):
        print('Resultat = ',self.flag)
        return(self.flag)
 
 
# Division de la fenetre en 3 "volets" redimensionnables
class Pane(object):
 
    def __init__(self, boss):
        self.fen = boss
 
        # création 
        self.pane1 = PanedWindow(self.fen, showhandle=1, sashrelief=SUNKEN, orient=HORIZONTAL) ;# ou VERTICAL
        self.pane1.pack(expand='yes',fill="both")
 
        self.pane2 = PanedWindow(self.pane1, showhandle=1, sashrelief=SUNKEN, orient=VERTICAL)
        self.pane1.add(self.pane2)
        ##pane2.pack(expand='yes',fill="both")
 
        self.gauche = Text(self.pane2, bg="red")
        self.milieu = Text(self.pane1, bg="yellow")
        self.droite = Text(self.pane1, bg="white")
 
        self.pane2.add(self.gauche)
        self.pane1.add(self.droite)
        self.pane1.add(self.milieu)
 
 
class Application(object):
 
    def __init__(self):
        self.Ecran = Tk()
        self.Ecran.geometry("300x150")
        f = Pane(self.Ecran)
        g = Detection_touche(self.Ecran)
        # récupération de la touche
        lambda f : g.Appui()
        # et insertion dans la zone texte 'gauche'
        f.gauche.insert(END, f)
        self.Ecran.mainloop()
 
 
app = Application() | 
Partager