title
= 'Pmw.PanedWidget demonstration'
# Import Pmw from this directory tree.
sys
.path
[:0] = ['../../..']
def __init__(self
, parent
):
# Create a main PanedWidget with a few panes.
self
.pw
= Pmw
.PanedWidget(parent
,
for self
.numPanes
in range(4):
pane
= self
.pw
.add(name
, min = .1, max = .1)
name
= 'Pane ' + str(self
.numPanes
)
pane
= self
.pw
.add(name
, min = .1, size
= .25)
label
= Tkinter
.Label(pane
, text
= name
)
label
.pack(side
= 'left', expand
= 1)
button
= Tkinter
.Button(pane
, text
= 'Delete',
command
= lambda s
=self
, n
=name
: s
.deletePane(n
))
button
.pack(side
= 'left', expand
= 1)
# TODO: add buttons to invoke self.moveOneUp and self.moveOneUp.
self
.pw
.pack(expand
= 1, fill
='both')
buttonBox
= Pmw
.ButtonBox(parent
)
buttonBox
.pack(fill
= 'x')
buttonBox
.add('Add pane', command
= self
.addPane
)
buttonBox
.add('Move pane', command
= self
.move
)
numPanes
= len(self
.pw
.panes())
print 'No panes to move!'
if self
.moveSrc
>= numPanes
:
self
.moveSrc
= numPanes
- 1
if self
.moveNewPos
>= numPanes
:
self
.moveNewPos
= numPanes
- 1
print 'Moving pane', self
.moveSrc
, 'to new position', self
.moveNewPos
self
.pw
.move(self
.moveSrc
, self
.moveNewPos
)
self
.moveSrc
, self
.moveNewPos
= self
.moveNewPos
, self
.moveSrc
if self
.moveNewPos
== numPanes
- 1:
if self
.moveSrc
== numPanes
- 1:
self
.moveSrc
= self
.moveSrc
+ 1
self
.moveNewPos
= self
.moveNewPos
+ 1
self
.moveBack
= not self
.moveBack
self
.numPanes
= self
.numPanes
+ 1
name
= 'Pane ' + str(self
.numPanes
)
pane
= self
.pw
.add(name
, min = .1, size
= .25)
label
= Tkinter
.Label(pane
, text
= name
)
label
.pack(side
= 'left', expand
= 1)
button
= Tkinter
.Button(pane
, text
= 'Delete',
command
= lambda s
=self
, n
=name
: s
.deletePane(n
))
button
.pack(side
= 'left', expand
= 1)
def deletePane(self
, name
):
def moveOneUp(self
, name
):
self
.pw
.move(name
, name
, -1)
def moveOneDown(self
, name
):
self
.pw
.move(name
, name
, 1)
######################################################################
# Create demo in root window for testing.
if __name__
== '__main__':
exitButton
= Tkinter
.Button(root
, text
= 'Exit', command
= root
.destroy
)
exitButton
.pack(side
= 'bottom')