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
| import Tkinter
from Tkinter import *
#params globaux
width = 28
height = 5
def TestGUI () :
# classe Cell = 2 frames superposees : 1 visible + 1 invisible
class Cell:
def __init__(self,x,y):
self.visible = 0 # indice de la frame visible
self.frame = [None,None] # les 2 frames superposees
self.x,self.y = x,y # coord de la frame
def clic( self,event=None ):
self.frame[self.visible].grid_forget() # rend la frame invisible
self.visible = 1-self.visible # inverse les visibilites des 2 frames
self.frame[self.visible].grid( column=self.x,row=self.y,sticky=Tkinter.NSEW ) # rend la frame visible
grid = [[ Cell(x,y) for x in xrange( 2 ) ] for y in xrange( 2 ) ]
root = Tkinter.Tk()
frame = Tkinter.Frame( root )
root.bind('<Escape>',lambda e : root.quit())
# cree 4 frames disposees en 2 x 2
for y in xrange( 2 ):
for x in xrange( 2 ):
cell = grid[y][x]
cell.frame[0] = Tkinter.LabelFrame( frame,relief =Tkinter.SUNKEN , borderwidth = 4)
txt = Tkinter.Label( cell.frame[0],width=width,height=height,
text ='very\nvery\nvery\nvery big\nand very very very large framed,%d'%(x))
txt.pack( expand = 1 )
txt.bind('<Button-1>',cell.clic )
cell.frame[0].grid( column=x,row=y,sticky=Tkinter.NSEW )
cell.frame[1] = Tkinter.LabelFrame( frame,relief =Tkinter.RAISED , borderwidth = 4)
txt = Tkinter.Label( cell.frame[1],width=width,height=height,text = 'small frame %d,%d'%(x,y))
txt.pack( expand = 1 )
txt.bind('<Button-1>',cell.clic )
cell.frame[1].grid( column=x,row=y,sticky=Tkinter.NSEW )
"""
if 1: # pour pouvoir deconnecter ce code rapidement
sx = max( cell.frame[0].cget('width'),cell.frame[1].cget('width'))
sy = max(cell.frame[0].cget('height'),cell.frame[1].cget('height'))
print 'cget --> %d,%d'%(sx,sy)
sx,sy = 25,25 # force les valeurs en dur
cell.frame[0].configure( width=sx , height=sy )
cell.frame[1].configure( width=sx , height=sy )
if 1 : # avec ou sans, ca ne marche pas...
cell.frame[0].grid_propagate( False )
cell.frame[1].grid_propagate( False )
"""
cell.clic()
frame.pack()
root.mainloop()
TestGUI() |
Partager