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
| 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 'break'
def Relache(self, event):
print ("relache : touche=",event.keysym)
print('')
self.flag = 'abc'
# 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.pane3 = PanedWindow(pane1, showhandle=1, sashrelief=SUNKEN, orient=VERTICAL)
## self.pane1.add(pane3)
self.left = Label(self.pane1,text="Côté gauche",bg="yellow")
self.right = Label(self.pane1,text="Côté droite",bg="white")
self.other = Label(self.pane2,text="Côté autre",bg="red")
self.pane1.add(self.left)
self.pane1.add(self.right)
self.pane2.add(self.other)
class Application(object):
def __init__(self):
self.Ecran = Tk()
self.Ecran.geometry("300x150")
f = Pane(self.Ecran)
## g = Detection_touche(f.pane1)
self.Ecran.mainloop()
app = Application() |
Partager