Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
21891d60
Commit
21891d60
authored
Jul 30, 1996
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated for Python 1.4
parent
437b77ab
Changes
43
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
43 changed files
with
738 additions
and
968 deletions
+738
-968
Demo/tkinter/guido/AttrDialog.py
Demo/tkinter/guido/AttrDialog.py
+47
-58
Demo/tkinter/guido/ManPage.py
Demo/tkinter/guido/ManPage.py
+14
-14
Demo/tkinter/guido/ShellWindow.py
Demo/tkinter/guido/ShellWindow.py
+43
-58
Demo/tkinter/guido/dialog.py
Demo/tkinter/guido/dialog.py
+30
-39
Demo/tkinter/guido/electrons.py
Demo/tkinter/guido/electrons.py
+5
-6
Demo/tkinter/guido/hanoi.py
Demo/tkinter/guido/hanoi.py
+6
-7
Demo/tkinter/guido/kill.py
Demo/tkinter/guido/kill.py
+41
-62
Demo/tkinter/guido/listtree.py
Demo/tkinter/guido/listtree.py
+6
-5
Demo/tkinter/guido/svkill.py
Demo/tkinter/guido/svkill.py
+43
-64
Demo/tkinter/guido/tkman.py
Demo/tkinter/guido/tkman.py
+58
-74
Demo/tkinter/matt/00-HELLO-WORLD.py
Demo/tkinter/matt/00-HELLO-WORLD.py
+6
-9
Demo/tkinter/matt/animation-simple.py
Demo/tkinter/matt/animation-simple.py
+6
-7
Demo/tkinter/matt/animation-w-velocity-ctrl.py
Demo/tkinter/matt/animation-w-velocity-ctrl.py
+8
-15
Demo/tkinter/matt/bind-w-mult-calls-p-type.py
Demo/tkinter/matt/bind-w-mult-calls-p-type.py
+3
-2
Demo/tkinter/matt/canvas-demo-simple.py
Demo/tkinter/matt/canvas-demo-simple.py
+6
-8
Demo/tkinter/matt/canvas-gridding.py
Demo/tkinter/matt/canvas-gridding.py
+12
-11
Demo/tkinter/matt/canvas-moving-or-creating.py
Demo/tkinter/matt/canvas-moving-or-creating.py
+20
-25
Demo/tkinter/matt/canvas-moving-w-mouse.py
Demo/tkinter/matt/canvas-moving-w-mouse.py
+13
-17
Demo/tkinter/matt/canvas-mult-item-sel.py
Demo/tkinter/matt/canvas-mult-item-sel.py
+24
-28
Demo/tkinter/matt/canvas-reading-tag-info.py
Demo/tkinter/matt/canvas-reading-tag-info.py
+10
-12
Demo/tkinter/matt/canvas-w-widget-draw-el.py
Demo/tkinter/matt/canvas-w-widget-draw-el.py
+8
-11
Demo/tkinter/matt/canvas-with-scrollbars.py
Demo/tkinter/matt/canvas-with-scrollbars.py
+18
-25
Demo/tkinter/matt/dialog-box.py
Demo/tkinter/matt/dialog-box.py
+40
-41
Demo/tkinter/matt/entry-with-shared-variable.py
Demo/tkinter/matt/entry-with-shared-variable.py
+3
-3
Demo/tkinter/matt/killing-window-w-wm.py
Demo/tkinter/matt/killing-window-w-wm.py
+2
-3
Demo/tkinter/matt/menu-all-types-of-entries.py
Demo/tkinter/matt/menu-all-types-of-entries.py
+64
-82
Demo/tkinter/matt/menu-simple.py
Demo/tkinter/matt/menu-simple.py
+19
-34
Demo/tkinter/matt/not-what-you-might-think-1.py
Demo/tkinter/matt/not-what-you-might-think-1.py
+7
-11
Demo/tkinter/matt/not-what-you-might-think-2.py
Demo/tkinter/matt/not-what-you-might-think-2.py
+7
-14
Demo/tkinter/matt/packer-and-placer-together.py
Demo/tkinter/matt/packer-and-placer-together.py
+7
-15
Demo/tkinter/matt/packer-simple.py
Demo/tkinter/matt/packer-simple.py
+9
-12
Demo/tkinter/matt/placer-simple.py
Demo/tkinter/matt/placer-simple.py
+7
-15
Demo/tkinter/matt/pong-demo-1.py
Demo/tkinter/matt/pong-demo-1.py
+10
-15
Demo/tkinter/matt/printing-coords-of-items.py
Demo/tkinter/matt/printing-coords-of-items.py
+18
-23
Demo/tkinter/matt/radiobutton-simple.py
Demo/tkinter/matt/radiobutton-simple.py
+22
-26
Demo/tkinter/matt/rubber-band-box-demo-1.py
Demo/tkinter/matt/rubber-band-box-demo-1.py
+11
-10
Demo/tkinter/matt/rubber-line-demo-1.py
Demo/tkinter/matt/rubber-line-demo-1.py
+10
-9
Demo/tkinter/matt/slider-demo-1.py
Demo/tkinter/matt/slider-demo-1.py
+15
-19
Demo/tkinter/matt/subclass-existing-widgets.py
Demo/tkinter/matt/subclass-existing-widgets.py
+5
-9
Demo/tkinter/matt/two-radio-groups.py
Demo/tkinter/matt/two-radio-groups.py
+29
-37
Demo/tkinter/matt/window-creation-more.py
Demo/tkinter/matt/window-creation-more.py
+11
-13
Demo/tkinter/matt/window-creation-simple.py
Demo/tkinter/matt/window-creation-simple.py
+7
-10
Demo/tkinter/matt/window-creation-w-location.py
Demo/tkinter/matt/window-creation-w-location.py
+8
-10
No files found.
Demo/tkinter/guido/AttrDialog.py
View file @
21891d60
...
@@ -24,12 +24,10 @@ class Option:
...
@@ -24,12 +24,10 @@ class Option:
self
.
master
=
dialog
.
top
self
.
master
=
dialog
.
top
self
.
default
,
self
.
klass
=
dialog
.
options
[
option
]
self
.
default
,
self
.
klass
=
dialog
.
options
[
option
]
self
.
var
=
self
.
varclass
(
self
.
master
)
self
.
var
=
self
.
varclass
(
self
.
master
)
self
.
frame
=
Frame
(
self
.
master
,
self
.
frame
=
Frame
(
self
.
master
)
{
Pack
:
{
'expand'
:
0
,
'fill'
:
'x'
}})
self
.
frame
.
pack
(
fill
=
X
)
self
.
label
=
Label
(
self
.
frame
,
self
.
label
=
Label
(
self
.
frame
,
text
=
(
option
+
":"
))
{
'text'
:
option
+
':'
,
self
.
label
.
pack
(
side
=
LEFT
)
Pack
:
{
'side'
:
'left'
},
})
self
.
update
()
self
.
update
()
self
.
addoption
()
self
.
addoption
()
...
@@ -53,55 +51,48 @@ class BooleanOption(Option):
...
@@ -53,55 +51,48 @@ class BooleanOption(Option):
def
addoption
(
self
):
def
addoption
(
self
):
self
.
button
=
Checkbutton
(
self
.
frame
,
self
.
button
=
Checkbutton
(
self
.
frame
,
{
'text'
:
'on/off'
,
text
=
'on/off'
,
'onvalue'
:
'1'
,
onvalue
=
1
,
'offvalue'
:
'0'
,
offvalue
=
0
,
'variable'
:
self
.
var
,
variable
=
self
.
var
,
'relief'
:
'raised'
,
relief
=
RAISED
,
'borderwidth'
:
2
,
borderwidth
=
2
,
'command'
:
self
.
set
,
command
=
self
.
set
)
Pack
:
{
'side'
:
'right'
},
self
.
button
.
pack
(
side
=
RIGHT
)
})
class
EnumOption
(
Option
):
class
EnumOption
(
Option
):
def
addoption
(
self
):
def
addoption
(
self
):
self
.
button
=
Menubutton
(
self
.
frame
,
self
.
button
=
Menubutton
(
self
.
frame
,
{
'textvariable'
:
self
.
var
,
textvariable
=
self
.
var
,
'relief'
:
'raised'
,
relief
=
RAISED
,
borderwidth
=
2
)
'borderwidth'
:
2
,
self
.
button
.
pack
(
side
=
RIGHT
)
Pack
:
{
'side'
:
'right'
},
})
self
.
menu
=
Menu
(
self
.
button
)
self
.
menu
=
Menu
(
self
.
button
)
self
.
button
[
'menu'
]
=
self
.
menu
self
.
button
[
'menu'
]
=
self
.
menu
for
v
in
self
.
dialog
.
classes
[
self
.
klass
]:
for
v
in
self
.
dialog
.
classes
[
self
.
klass
]:
self
.
menu
.
add_radiobutton
(
self
.
menu
.
add_radiobutton
(
{
'label'
:
v
,
label
=
v
,
'variable'
:
self
.
var
,
variable
=
self
.
var
,
'value'
:
v
,
value
=
v
,
'command'
:
self
.
set
,
command
=
self
.
set
)
})
class
StringOption
(
Option
):
class
StringOption
(
Option
):
def
addoption
(
self
):
def
addoption
(
self
):
self
.
entry
=
Entry
(
self
.
frame
,
self
.
entry
=
Entry
(
self
.
frame
,
{
'textvariable'
:
self
.
var
,
textvariable
=
self
.
var
,
'width'
:
10
,
width
=
10
,
'relief'
:
'sunken'
,
relief
=
SUNKEN
,
'borderwidth'
:
2
,
borderwidth
=
2
)
Pack
:
{
'side'
:
'right'
,
self
.
entry
.
pack
(
side
=
RIGHT
,
fill
=
X
,
expand
=
1
)
'fill'
:
'x'
,
'expand'
:
1
},
})
self
.
entry
.
bind
(
'<Return>'
,
self
.
set
)
self
.
entry
.
bind
(
'<Return>'
,
self
.
set
)
class
ReadonlyOption
(
Option
):
class
ReadonlyOption
(
Option
):
def
addoption
(
self
):
def
addoption
(
self
):
self
.
label
=
Label
(
self
.
frame
,
self
.
label
=
Label
(
self
.
frame
,
textvariable
=
self
.
var
,
{
'textvariable'
:
self
.
var
,
anchor
=
E
)
'anchor'
:
'e'
,
self
.
label
.
pack
(
side
=
RIGHT
)
Pack
:
{
'side'
:
'right'
}})
class
Dialog
:
class
Dialog
:
...
@@ -156,7 +147,7 @@ class PackDialog(Dialog):
...
@@ -156,7 +147,7 @@ class PackDialog(Dialog):
Dialog
.
__init__
(
self
,
widget
)
Dialog
.
__init__
(
self
,
widget
)
def
refresh
(
self
):
def
refresh
(
self
):
self
.
current
=
self
.
widget
.
new
info
()
self
.
current
=
self
.
widget
.
info
()
self
.
current
[
'.class'
]
=
self
.
widget
.
winfo_class
()
self
.
current
[
'.class'
]
=
self
.
widget
.
winfo_class
()
self
.
current
[
'.name'
]
=
self
.
widget
.
_w
self
.
current
[
'.name'
]
=
self
.
widget
.
_w
...
@@ -164,8 +155,8 @@ class PackDialog(Dialog):
...
@@ -164,8 +155,8 @@ class PackDialog(Dialog):
def
set
(
self
,
e
=
None
):
def
set
(
self
,
e
=
None
):
self
.
current
=
self
.
var
.
get
()
self
.
current
=
self
.
var
.
get
()
try
:
try
:
Pack
.
config
(
self
.
dialog
.
widget
,
apply
(
self
.
dialog
.
widget
.
pack
,
()
,
{
self
.
option
:
self
.
current
})
{
self
.
option
:
self
.
current
})
except
TclError
,
msg
:
except
TclError
,
msg
:
print
msg
print
msg
self
.
refresh
()
self
.
refresh
()
...
@@ -192,14 +183,14 @@ class PackDialog(Dialog):
...
@@ -192,14 +183,14 @@ class PackDialog(Dialog):
}
}
classes
=
{
classes
=
{
'Anchor'
:
(
'n'
,
'ne'
,
'e'
,
'se'
,
's'
,
'sw'
,
'w'
,
'nw'
,
'center'
),
'Anchor'
:
(
N
,
NE
,
E
,
SE
,
S
,
SW
,
W
,
NW
,
CENTER
),
'Boolean'
:
'boolean'
,
'Boolean'
:
'boolean'
,
'Class'
:
'readonly'
,
'Class'
:
'readonly'
,
'Expand'
:
'boolean'
,
'Expand'
:
'boolean'
,
'Fill'
:
(
'none'
,
'x'
,
'y'
,
'both'
),
'Fill'
:
(
NONE
,
X
,
Y
,
BOTH
),
'Name'
:
'readonly'
,
'Name'
:
'readonly'
,
'Pad'
:
'pixel'
,
'Pad'
:
'pixel'
,
'Side'
:
(
'top'
,
'right'
,
'bottom'
,
'left'
),
'Side'
:
(
TOP
,
RIGHT
,
BOTTOM
,
LEFT
),
'Widget'
:
'readonly'
,
'Widget'
:
'readonly'
,
}
}
...
@@ -220,7 +211,7 @@ class RemotePackDialog(PackDialog):
...
@@ -220,7 +211,7 @@ class RemotePackDialog(PackDialog):
words
=
self
.
master
.
tk
.
splitlist
(
words
=
self
.
master
.
tk
.
splitlist
(
self
.
master
.
send
(
self
.
app
,
self
.
master
.
send
(
self
.
app
,
'pack'
,
'pack'
,
'
new
info'
,
'info'
,
self
.
widget
))
self
.
widget
))
except
TclError
,
msg
:
except
TclError
,
msg
:
print
msg
print
msg
...
@@ -306,7 +297,7 @@ class WidgetDialog(Dialog):
...
@@ -306,7 +297,7 @@ class WidgetDialog(Dialog):
# Universal classes
# Universal classes
classes
=
{
classes
=
{
'Anchor'
:
(
'n'
,
'ne'
,
'e'
,
'se'
,
's'
,
'sw'
,
'w'
,
'nw'
,
'center'
),
'Anchor'
:
(
N
,
NE
,
E
,
SE
,
S
,
SW
,
W
,
NW
,
CENTER
),
'Aspect'
:
'integer'
,
'Aspect'
:
'integer'
,
'Background'
:
'color'
,
'Background'
:
'color'
,
'Bitmap'
:
'bitmap'
,
'Bitmap'
:
'bitmap'
,
...
@@ -325,16 +316,16 @@ class WidgetDialog(Dialog):
...
@@ -325,16 +316,16 @@ class WidgetDialog(Dialog):
'Geometry'
:
'geometry'
,
'Geometry'
:
'geometry'
,
'Height'
:
'pixel'
,
'Height'
:
'pixel'
,
'InsertWidth'
:
'time'
,
'InsertWidth'
:
'time'
,
'Justify'
:
(
'left'
,
'center'
,
'right'
),
'Justify'
:
(
LEFT
,
CENTER
,
RIGHT
),
'Label'
:
'string'
,
'Label'
:
'string'
,
'Length'
:
'pixel'
,
'Length'
:
'pixel'
,
'MenuName'
:
'widget'
,
'MenuName'
:
'widget'
,
'Name'
:
'readonly'
,
'Name'
:
'readonly'
,
'OffTime'
:
'time'
,
'OffTime'
:
'time'
,
'OnTime'
:
'time'
,
'OnTime'
:
'time'
,
'Orient'
:
(
'horizontal'
,
'vertical'
),
'Orient'
:
(
HORIZONTAL
,
VERTICAL
),
'Pad'
:
'pixel'
,
'Pad'
:
'pixel'
,
'Relief'
:
(
'raised'
,
'sunken'
,
'flat'
,
'ridge'
,
'groove'
),
'Relief'
:
(
RAISED
,
SUNKEN
,
FLAT
,
RIDGE
,
GROOVE
),
'RepeatDelay'
:
'time'
,
'RepeatDelay'
:
'time'
,
'RepeatInterval'
:
'time'
,
'RepeatInterval'
:
'time'
,
'ScrollCommand'
:
'command'
,
'ScrollCommand'
:
'command'
,
...
@@ -351,12 +342,12 @@ class WidgetDialog(Dialog):
...
@@ -351,12 +342,12 @@ class WidgetDialog(Dialog):
'Variable'
:
'variable'
,
'Variable'
:
'variable'
,
'Value'
:
'string'
,
'Value'
:
'string'
,
'Width'
:
'pixel'
,
'Width'
:
'pixel'
,
'Wrap'
:
(
'none'
,
'char'
,
'word'
),
'Wrap'
:
(
NONE
,
CHAR
,
WORD
),
}
}
# Classes that (may) differ per widget type
# Classes that (may) differ per widget type
_tristate
=
{
'State'
:
(
'normal'
,
'active'
,
'disabled'
)}
_tristate
=
{
'State'
:
(
NORMAL
,
ACTIVE
,
DISABLED
)}
_bistate
=
{
'State'
:
(
'normal'
,
'disabled'
)}
_bistate
=
{
'State'
:
(
NORMAL
,
DISABLED
)}
addclasses
=
{
addclasses
=
{
'Button'
:
_tristate
,
'Button'
:
_tristate
,
'Radiobutton'
:
_tristate
,
'Radiobutton'
:
_tristate
,
...
@@ -424,14 +415,12 @@ def test():
...
@@ -424,14 +415,12 @@ def test():
if
sys
.
argv
[
1
:]:
if
sys
.
argv
[
1
:]:
remotetest
(
root
,
sys
.
argv
[
1
])
remotetest
(
root
,
sys
.
argv
[
1
])
else
:
else
:
frame
=
Frame
(
root
,
{
'name'
:
'frame'
,
frame
=
Frame
(
root
,
name
=
'frame'
)
Pack
:
{
'expand'
:
1
,
'fill'
:
'both'
},
frame
.
pack
(
expand
=
1
,
fill
=
BOTH
)
})
button
=
Button
(
frame
,
name
=
'button'
,
text
=
'button'
)
button
=
Button
(
frame
,
{
'name'
:
'button'
,
button
.
pack
(
expand
=
1
)
'text'
:
'button'
,
canvas
=
Canvas
(
frame
,
name
=
'canvas'
)
Pack
:
{
'expand'
:
1
}})
canvas
.
pack
()
canvas
=
Canvas
(
frame
,
{
'name'
:
'canvas'
,
Pack
:
{}})
fpd
=
PackDialog
(
frame
)
fpd
=
PackDialog
(
frame
)
fwd
=
WidgetDialog
(
frame
)
fwd
=
WidgetDialog
(
frame
)
bpd
=
PackDialog
(
button
)
bpd
=
PackDialog
(
button
)
...
...
Demo/tkinter/guido/ManPage.py
View file @
21891d60
...
@@ -20,14 +20,14 @@ ulprog = regex.compile('^[ \t]*[Xv!_][Xv!_ \t]*\n')
...
@@ -20,14 +20,14 @@ ulprog = regex.compile('^[ \t]*[Xv!_][Xv!_ \t]*\n')
class
EditableManPage
(
ScrolledText
):
class
EditableManPage
(
ScrolledText
):
# Initialize instance
# Initialize instance
def
__init__
(
self
,
master
=
None
,
cnf
=
{}
):
def
__init__
(
self
,
master
=
None
,
**
cnf
):
# Initialize base class
# Initialize base class
ScrolledText
.
__init__
(
self
,
master
,
cnf
)
apply
(
ScrolledText
.
__init__
,
(
self
,
master
)
,
cnf
)
# Define tags for formatting styles
# Define tags for formatting styles
self
.
tag_config
(
'X'
,
{
'underline'
:
1
}
)
self
.
tag_config
(
'X'
,
underline
=
1
)
self
.
tag_config
(
'!'
,
{
'font'
:
BOLDFONT
}
)
self
.
tag_config
(
'!'
,
font
=
BOLDFONT
)
self
.
tag_config
(
'_'
,
{
'font'
:
ITALICFONT
}
)
self
.
tag_config
(
'_'
,
font
=
ITALICFONT
)
# Set state to idle
# Set state to idle
self
.
fp
=
None
self
.
fp
=
None
...
@@ -83,8 +83,8 @@ class EditableManPage(ScrolledText):
...
@@ -83,8 +83,8 @@ class EditableManPage(ScrolledText):
self
.
empty
=
0
self
.
empty
=
0
self
.
buffer
=
None
self
.
buffer
=
None
savestate
=
self
[
'state'
]
savestate
=
self
[
'state'
]
self
[
'state'
]
=
'normal'
self
[
'state'
]
=
NORMAL
self
.
delete
(
'1.0'
,
'end'
)
self
.
delete
(
'1.0'
,
END
)
self
[
'state'
]
=
savestate
self
[
'state'
]
=
savestate
# End parsing -- must be busy, need not be at EOF
# End parsing -- must be busy, need not be at EOF
...
@@ -133,11 +133,11 @@ class EditableManPage(ScrolledText):
...
@@ -133,11 +133,11 @@ class EditableManPage(ScrolledText):
self
.
empty
=
0
self
.
empty
=
0
return
return
savestate
=
self
[
'state'
]
savestate
=
self
[
'state'
]
self
[
'state'
]
=
'normal'
self
[
'state'
]
=
NORMAL
if
TkVersion
>=
4.0
:
if
TkVersion
>=
4.0
:
self
.
mark_set
(
'insert'
,
'end-1c'
)
self
.
mark_set
(
'insert'
,
'end-1c'
)
else
:
else
:
self
.
mark_set
(
'insert'
,
'end'
)
self
.
mark_set
(
'insert'
,
END
)
if
self
.
empty
:
if
self
.
empty
:
# One or more previous lines were empty
# One or more previous lines were empty
# -- insert one blank line in the text
# -- insert one blank line in the text
...
@@ -176,9 +176,9 @@ class EditableManPage(ScrolledText):
...
@@ -176,9 +176,9 @@ class EditableManPage(ScrolledText):
class
ReadonlyManPage
(
EditableManPage
):
class
ReadonlyManPage
(
EditableManPage
):
# Initialize instance
# Initialize instance
def
__init__
(
self
,
master
=
None
,
cnf
=
{}
):
def
__init__
(
self
,
master
=
None
,
**
cnf
):
EditableManPage
.
__init__
(
self
,
master
,
cnf
[
'state'
]
=
DISABLED
(
cnf
,
{
'state'
:
'disabled'
})
)
apply
(
EditableManPage
.
__init__
,
(
self
,
master
),
cnf
)
# Alias
# Alias
ManPage
=
ReadonlyManPage
ManPage
=
ReadonlyManPage
...
@@ -206,8 +206,8 @@ def test():
...
@@ -206,8 +206,8 @@ def test():
name
=
os
.
path
.
join
(
MANDIR
,
name
)
name
=
os
.
path
.
join
(
MANDIR
,
name
)
root
=
Tk
()
root
=
Tk
()
root
.
minsize
(
1
,
1
)
root
.
minsize
(
1
,
1
)
manpage
=
ManPage
(
root
,
{
'relief'
:
'sunken'
,
'bd'
:
2
,
manpage
=
ManPage
(
root
,
relief
=
SUNKEN
,
borderwidth
=
2
)
Pack
:
{
'expand'
:
1
,
'fill'
:
'both'
}}
)
manpage
.
pack
(
expand
=
1
,
fill
=
BOTH
)
if
formatted
:
if
formatted
:
fp
=
open
(
name
,
'r'
)
fp
=
open
(
name
,
'r'
)
else
:
else
:
...
...
Demo/tkinter/guido/ShellWindow.py
View file @
21891d60
...
@@ -6,19 +6,12 @@ from ScrolledText import ScrolledText
...
@@ -6,19 +6,12 @@ from ScrolledText import ScrolledText
from
Dialog
import
Dialog
from
Dialog
import
Dialog
import
signal
import
signal
TK_READABLE
=
1
TK_WRITABLE
=
2
TK_EXCEPTION
=
4
BUFSIZE
=
512
BUFSIZE
=
512
class
ShellWindow
(
ScrolledText
):
class
ShellWindow
(
ScrolledText
):
def
__init__
(
self
,
master
=
None
,
cnf
=
{}):
def
__init__
(
self
,
master
=
None
,
shell
=
None
,
**
cnf
):
try
:
if
not
shell
:
shell
=
cnf
[
'shell'
]
del
cnf
[
'shell'
]
except
KeyError
:
try
:
try
:
shell
=
os
.
environ
[
'SHELL'
]
shell
=
os
.
environ
[
'SHELL'
]
except
KeyError
:
except
KeyError
:
...
@@ -27,7 +20,7 @@ class ShellWindow(ScrolledText):
...
@@ -27,7 +20,7 @@ class ShellWindow(ScrolledText):
args
=
string
.
split
(
shell
)
args
=
string
.
split
(
shell
)
shell
=
args
[
0
]
shell
=
args
[
0
]
ScrolledText
.
__init__
(
self
,
master
,
cnf
)
apply
(
ScrolledText
.
__init__
,
(
self
,
master
)
,
cnf
)
self
.
pos
=
'1.0'
self
.
pos
=
'1.0'
self
.
bind
(
'<Return>'
,
self
.
inputhandler
)
self
.
bind
(
'<Return>'
,
self
.
inputhandler
)
self
.
bind
(
'<Control-c>'
,
self
.
sigint
)
self
.
bind
(
'<Control-c>'
,
self
.
sigint
)
...
@@ -36,7 +29,7 @@ class ShellWindow(ScrolledText):
...
@@ -36,7 +29,7 @@ class ShellWindow(ScrolledText):
self
.
bind
(
'<Control-d>'
,
self
.
sendeof
)
self
.
bind
(
'<Control-d>'
,
self
.
sendeof
)
self
.
pid
,
self
.
fromchild
,
self
.
tochild
=
spawn
(
shell
,
args
)
self
.
pid
,
self
.
fromchild
,
self
.
tochild
=
spawn
(
shell
,
args
)
self
.
tk
.
createfilehandler
(
self
.
fromchild
,
TK_
READABLE
,
self
.
tk
.
createfilehandler
(
self
.
fromchild
,
READABLE
,
self
.
outputhandler
)
self
.
outputhandler
)
def
outputhandler
(
self
,
file
,
mask
):
def
outputhandler
(
self
,
file
,
mask
):
...
@@ -54,68 +47,60 @@ class ShellWindow(ScrolledText):
...
@@ -54,68 +47,60 @@ class ShellWindow(ScrolledText):
msg
=
"killed by signal %d"
%
(
cause
&
0x7f
)
msg
=
"killed by signal %d"
%
(
cause
&
0x7f
)
if
cause
&
0x80
:
if
cause
&
0x80
:
msg
=
msg
+
" -- core dumped"
msg
=
msg
+
" -- core dumped"
Dialog
(
self
.
master
,
{
Dialog
(
self
.
master
,
'text'
:
msg
,
text
=
msg
,
'title'
:
"Exit status"
,
title
=
"Exit status"
,
'bitmap'
:
'warning'
,
bitmap
=
'warning'
,
'default'
:
0
,
default
=
0
,
'strings'
:
(
'OK'
,),
strings
=
(
'OK'
,))
})
return
return
self
.
insert
(
'end'
,
data
)
self
.
insert
(
END
,
data
)
self
.
pos
=
self
.
index
(
'end'
)
self
.
pos
=
self
.
index
(
"end - 1 char"
)
self
.
yview_pickplace
(
'end'
)
self
.
yview_pickplace
(
END
)
def
inputhandler
(
self
,
*
args
):
def
inputhandler
(
self
,
*
args
):
if
not
self
.
pid
:
if
not
self
.
pid
:
Dialog
(
self
.
master
,
{
self
.
no_process
()
'text'
:
"No active process"
,
return
"break"
'title'
:
"No process"
,
self
.
insert
(
END
,
"
\
n
"
)
'bitmap'
:
'error'
,
line
=
self
.
get
(
self
.
pos
,
"end - 1 char"
)
'default'
:
0
,
self
.
pos
=
self
.
index
(
END
)
'strings'
:
(
'OK'
,),
})
return
self
.
insert
(
'end'
,
'
\
n
'
)
line
=
self
.
get
(
self
.
pos
,
'end'
)
self
.
pos
=
self
.
index
(
'end'
)
os
.
write
(
self
.
tochild
,
line
)
os
.
write
(
self
.
tochild
,
line
)
return
"break"
def
sendeof
(
self
,
*
args
):
def
sendeof
(
self
,
*
args
):
if
not
self
.
pid
:
if
not
self
.
pid
:
Dialog
(
self
.
master
,
{
self
.
no_process
()
'text'
:
"No active process"
,
return
"break"
'title'
:
"No process"
,
'bitmap'
:
'error'
,
'default'
:
0
,
'strings'
:
(
'OK'
,),
})
return
os
.
close
(
self
.
tochild
)
os
.
close
(
self
.
tochild
)
return
"break"
def
sendsig
(
self
,
sig
):
def
sendsig
(
self
,
sig
):
if
not
self
.
pid
:
if
not
self
.
pid
:
Dialog
(
self
.
master
,
{
self
.
no_process
()
'text'
:
"No active process"
,
return
"break"
'title'
:
"No process"
,
'bitmap'
:
'error'
,
'default'
:
0
,
'strings'
:
(
'OK'
,),
})
return
os
.
kill
(
self
.
pid
,
sig
)
os
.
kill
(
self
.
pid
,
sig
)
return
"break"
def
sigint
(
self
,
*
args
):
def
sigint
(
self
,
*
args
):
self
.
sendsig
(
signal
.
SIGINT
)
return
self
.
sendsig
(
signal
.
SIGINT
)
def
sigquit
(
self
,
*
args
):
def
sigquit
(
self
,
*
args
):
self
.
sendsig
(
signal
.
SIGQUIT
)
return
self
.
sendsig
(
signal
.
SIGQUIT
)
def
sigterm
(
self
,
*
args
):
def
sigterm
(
self
,
*
args
):
self
.
sendsig
(
signal
.
SIGTERM
)
return
self
.
sendsig
(
signal
.
SIGTERM
)
def
sigkill
(
self
,
*
args
):
def
sigkill
(
self
,
*
args
):
self
.
sendsig
(
signal
.
SIGKILL
)
return
self
.
sendsig
(
signal
.
SIGKILL
)
def
no_process
(
self
):
Dialog
(
self
.
master
,
text
=
"No active process"
,
title
=
"No process"
,
bitmap
=
'error'
,
default
=
0
,
strings
=
(
'OK'
,))
MAXFD
=
100
# Max number of file descriptors (os.getdtablesize()???)
MAXFD
=
100
# Max number of file descriptors (os.getdtablesize()???)
...
@@ -142,7 +127,7 @@ def spawn(prog, args):
...
@@ -142,7 +127,7 @@ def spawn(prog, args):
try
:
try
:
os
.
execvp
(
prog
,
args
)
os
.
execvp
(
prog
,
args
)
finally
:
finally
:
print
'execvp failed'
sys
.
stderr
.
write
(
'execvp failed
\
n
'
)
os
.
_exit
(
1
)
os
.
_exit
(
1
)
os
.
close
(
p2cread
)
os
.
close
(
p2cread
)
os
.
close
(
c2pwrite
)
os
.
close
(
c2pwrite
)
...
@@ -150,13 +135,13 @@ def spawn(prog, args):
...
@@ -150,13 +135,13 @@ def spawn(prog, args):
def
test
():
def
test
():
shell
=
string
.
join
(
sys
.
argv
[
1
:])
shell
=
string
.
join
(
sys
.
argv
[
1
:])
cnf
=
{}
if
shell
:
cnf
[
'shell'
]
=
shell
root
=
Tk
()
root
=
Tk
()
root
.
minsize
(
1
,
1
)
root
.
minsize
(
1
,
1
)
w
=
ShellWindow
(
root
,
cnf
)
if
shell
:
w
.
pack
({
'expand'
:
1
,
'fill'
:
'both'
})
w
=
ShellWindow
(
root
,
shell
=
shell
)
else
:
w
=
ShellWindow
(
root
)
w
.
pack
(
expand
=
1
,
fill
=
BOTH
)
w
.
focus_set
()
w
.
focus_set
()
w
.
tk
.
mainloop
()
w
.
tk
.
mainloop
()
...
...
Demo/tkinter/guido/dialog.py
View file @
21891d60
...
@@ -5,55 +5,49 @@
...
@@ -5,55 +5,49 @@
# Cf. Ousterhout, Tcl and the Tk Toolkit, Figs. 27.2-3, pp. 269-270.
# Cf. Ousterhout, Tcl and the Tk Toolkit, Figs. 27.2-3, pp. 269-270.
from
Tkinter
import
*
from
Tkinter
import
*
import
sys
def
dialog
(
master
,
title
,
text
,
bitmap
,
default
,
*
args
):
def
dialog
(
master
,
title
,
text
,
bitmap
,
default
,
*
args
):
# 1. Create the top-level window and divide it into top
# 1. Create the top-level window and divide it into top
# and bottom parts.
# and bottom parts.
w
=
Toplevel
(
master
,
{
'class'
:
'Dialog'
}
)
w
=
Toplevel
(
master
,
class_
=
'Dialog'
)
w
.
title
(
title
)
w
.
title
(
title
)
w
.
iconname
(
'Dialog'
)
w
.
iconname
(
'Dialog'
)
top
=
Frame
(
w
,
{
'relief'
:
'raised'
,
'bd'
:
1
,
top
=
Frame
(
w
,
relief
=
RAISED
,
borderwidth
=
1
)
Pack
:
{
'side'
:
'top'
,
'fill'
:
'both'
}}
)
top
.
pack
(
side
=
TOP
,
fill
=
BOTH
)
bot
=
Frame
(
w
,
{
'relief'
:
'raised'
,
'bd'
:
1
,
bot
=
Frame
(
w
,
relief
=
RAISED
,
borderwidth
=
1
)
Pack
:
{
'side'
:
'bottom'
,
'fill'
:
'both'
}}
)
bot
.
pack
(
side
=
BOTTOM
,
fill
=
BOTH
)
# 2. Fill the top part with the bitmap and message.
# 2. Fill the top part with the bitmap and message.
msg
=
Message
(
top
,
msg
=
Message
(
top
,
width
=
'3i'
,
text
=
text
,
{
'width'
:
'3i'
,
font
=
'-Adobe-Times-Medium-R-Normal-*-180-*'
)
'text'
:
text
,
msg
.
pack
(
side
=
RIGHT
,
expand
=
1
,
fill
=
BOTH
,
padx
=
'3m'
,
pady
=
'3m'
)
'font'
:
'-Adobe-Times-Medium-R-Normal-*-180-*'
,
Pack
:
{
'side'
:
'right'
,
'expand'
:
1
,
'fill'
:
'both'
,
'padx'
:
'3m'
,
'pady'
:
'3m'
}})
if
bitmap
:
if
bitmap
:
bm
=
Label
(
top
,
{
'bitmap'
:
bitmap
,
bm
=
Label
(
top
,
bitmap
=
bitmap
)
Pack
:
{
'side'
:
'left'
,
bm
.
pack
(
side
=
LEFT
,
padx
=
'3m'
,
pady
=
'3m'
)
'padx'
:
'3m'
,
'pady'
:
'3m'
}})
# 3. Create a row of buttons at the bottom of the dialog.
# 3. Create a row of buttons at the bottom of the dialog.
var
=
IntVar
()
buttons
=
[]
buttons
=
[]
i
=
0
i
=
0
for
but
in
args
:
for
but
in
args
:
b
=
Button
(
bot
,
{
'text'
:
but
,
b
=
Button
(
bot
,
text
=
but
,
command
=
lambda
v
=
var
,
i
=
i
:
v
.
set
(
i
))
'command'
:
(
'set'
,
'button'
,
i
)})
buttons
.
append
(
b
)
buttons
.
append
(
b
)
if
i
==
default
:
if
i
==
default
:
bd
=
Frame
(
bot
,
{
'relief'
:
'sunken'
,
'bd'
:
1
,
bd
=
Frame
(
bot
,
relief
=
SUNKEN
,
borderwidth
=
1
)
Pack
:
{
'side'
:
'left'
,
'expand'
:
1
,
bd
.
pack
(
side
=
LEFT
,
expand
=
1
,
padx
=
'3m'
,
pady
=
'2m'
)
'padx'
:
'3m'
,
'pady'
:
'2m'
}})
b
.
lift
()
b
.
lift
()
b
.
pack
({
'in'
:
bd
,
'side'
:
'left'
,
b
.
pack
(
in_
=
bd
,
side
=
LEFT
,
'padx'
:
'2m'
,
'pady'
:
'2m'
,
padx
=
'2m'
,
pady
=
'2m'
,
ipadx
=
'2m'
,
ipady
=
'1m'
)
'ipadx'
:
'2m'
,
'ipady'
:
'1m'
})
else
:
else
:
b
.
pack
({
'side'
:
'left'
,
'expand'
:
1
,
b
.
pack
(
side
=
LEFT
,
expand
=
1
,
'padx'
:
'3m'
,
'pady'
:
'3m'
,
padx
=
'3m'
,
pady
=
'3m'
,
ipady
=
'2m'
,
ipady
=
'1m'
)
'ipady'
:
'2m'
,
'ipady'
:
'1m'
})
i
=
i
+
1
i
=
i
+
1
# 4. Set up a binding for <Return>, if there's a default,
# 4. Set up a binding for <Return>, if there's a default,
...
@@ -61,21 +55,21 @@ def dialog(master, title, text, bitmap, default, *args):
...
@@ -61,21 +55,21 @@ def dialog(master, title, text, bitmap, default, *args):
if
default
>=
0
:
if
default
>=
0
:
w
.
bind
(
'<Return>'
,
w
.
bind
(
'<Return>'
,
lambda
e
,
b
=
buttons
[
default
],
i
=
default
:
lambda
e
,
b
=
buttons
[
default
],
v
=
var
,
i
=
default
:
(
b
.
flash
(),
(
b
.
flash
(),
b
.
setvar
(
'button'
,
i
)))
v
.
set
(
i
)))
oldFocus
=
w
.
tk
.
call
(
'focus'
)
# XXX
oldFocus
=
w
.
focus_get
()
w
.
grab_set
()
w
.
grab_set
()
w
.
focus
()
w
.
focus
_set
()
# 5. Wait for the user to respond, then restore the focus
# 5. Wait for the user to respond, then restore the focus
# and return the index of the selected button.
# and return the index of the selected button.
w
.
waitvar
(
'button'
)
w
.
waitvar
(
var
)
w
.
destroy
()
w
.
destroy
()
w
.
tk
.
call
(
'focus'
,
oldFocus
)
# XXX
if
oldFocus
:
oldFocus
.
focus_set
()
return
w
.
getint
(
w
.
getvar
(
'button'
)
)
return
var
.
get
(
)
# The rest is the test program.
# The rest is the test program.
...
@@ -105,13 +99,10 @@ def test():
...
@@ -105,13 +99,10 @@ def test():
global
mainWidget
global
mainWidget
mainWidget
=
Frame
()
mainWidget
=
Frame
()
Pack
.
config
(
mainWidget
)
Pack
.
config
(
mainWidget
)
start
=
Button
(
mainWidget
,
start
=
Button
(
mainWidget
,
text
=
'Press Here To Start'
,
command
=
go
)
{
'text'
:
'Press Here To Start'
,
'command'
:
go
})
start
.
pack
()
start
.
pack
()
endit
=
Button
(
mainWidget
,
endit
=
Button
(
mainWidget
,
text
=
"Exit"
,
command
=
sys
.
exit
)
{
'text'
:
'Exit'
,
endit
.
pack
(
fill
=
BOTH
)
'command'
:
'exit'
,
Pack
:
{
'fill'
:
'both'
}})
mainWidget
.
mainloop
()
mainWidget
.
mainloop
()
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
...
Demo/tkinter/guido/electrons.py
View file @
21891d60
...
@@ -15,7 +15,6 @@
...
@@ -15,7 +15,6 @@
from
Tkinter
import
*
from
Tkinter
import
*
# The graphical interface
# The graphical interface
class
Electrons
:
class
Electrons
:
...
@@ -30,14 +29,13 @@ class Electrons:
...
@@ -30,14 +29,13 @@ class Electrons:
# Add background bitmap
# Add background bitmap
if
bitmap
:
if
bitmap
:
self
.
bitmap
=
c
.
create_bitmap
(
width
/
2
,
height
/
2
,
self
.
bitmap
=
c
.
create_bitmap
(
width
/
2
,
height
/
2
,
{
'bitmap'
:
bitmap
,
bitmap
=
bitmap
,
'foreground'
:
'blue'
}
)
foreground
=
'blue'
)
self
.
pieces
=
{}
self
.
pieces
=
{}
x1
,
y1
,
x2
,
y2
=
10
,
70
,
14
,
74
x1
,
y1
,
x2
,
y2
=
10
,
70
,
14
,
74
for
i
in
range
(
n
,
0
,
-
1
):
for
i
in
range
(
n
,
0
,
-
1
):
p
=
c
.
create_oval
(
x1
,
y1
,
x2
,
y2
,
p
=
c
.
create_oval
(
x1
,
y1
,
x2
,
y2
,
fill
=
'red'
)
{
'fill'
:
'red'
})
self
.
pieces
[
i
]
=
p
self
.
pieces
[
i
]
=
p
y1
,
y2
=
y1
+
2
,
y2
+
2
y1
,
y2
=
y1
+
2
,
y2
+
2
self
.
tk
.
update
()
self
.
tk
.
update
()
...
@@ -51,11 +49,12 @@ class Electrons:
...
@@ -51,11 +49,12 @@ class Electrons:
y
=
rand
.
choice
(
range
(
-
3
,
4
))
y
=
rand
.
choice
(
range
(
-
3
,
4
))
c
.
move
(
p
,
x
,
y
)
c
.
move
(
p
,
x
,
y
)
self
.
tk
.
update
()
self
.
tk
.
update
()
# Run -- never returns
# Run -- never returns
def
run
(
self
):
def
run
(
self
):
while
1
:
while
1
:
self
.
random_move
(
self
.
n
)
self
.
random_move
(
self
.
n
)
self
.
tk
.
mainloop
()
# Hang around...
# Main program
# Main program
def
main
():
def
main
():
...
...
Demo/tkinter/guido/hanoi.py
View file @
21891d60
...
@@ -36,8 +36,8 @@ class Tkhanoi:
...
@@ -36,8 +36,8 @@ class Tkhanoi:
# Add background bitmap
# Add background bitmap
if
bitmap
:
if
bitmap
:
self
.
bitmap
=
c
.
create_bitmap
(
width
/
2
,
height
/
2
,
self
.
bitmap
=
c
.
create_bitmap
(
width
/
2
,
height
/
2
,
{
'bitmap'
:
bitmap
,
bitmap
=
bitmap
,
'foreground'
:
'blue'
}
)
foreground
=
'blue'
)
# Generate pegs
# Generate pegs
pegwidth
=
10
pegwidth
=
10
...
@@ -46,13 +46,13 @@ class Tkhanoi:
...
@@ -46,13 +46,13 @@ class Tkhanoi:
x1
,
y1
=
(
pegdist
-
pegwidth
)
/
2
,
height
*
1
/
3
x1
,
y1
=
(
pegdist
-
pegwidth
)
/
2
,
height
*
1
/
3
x2
,
y2
=
x1
+
pegwidth
,
y1
+
pegheight
x2
,
y2
=
x1
+
pegwidth
,
y1
+
pegheight
self
.
pegs
=
[]
self
.
pegs
=
[]
p
=
c
.
create_rectangle
(
x1
,
y1
,
x2
,
y2
,
{
'fill'
:
'black'
}
)
p
=
c
.
create_rectangle
(
x1
,
y1
,
x2
,
y2
,
fill
=
'black'
)
self
.
pegs
.
append
(
p
)
self
.
pegs
.
append
(
p
)
x1
,
x2
=
x1
+
pegdist
,
x2
+
pegdist
x1
,
x2
=
x1
+
pegdist
,
x2
+
pegdist
p
=
c
.
create_rectangle
(
x1
,
y1
,
x2
,
y2
,
{
'fill'
:
'black'
}
)
p
=
c
.
create_rectangle
(
x1
,
y1
,
x2
,
y2
,
fill
=
'black'
)
self
.
pegs
.
append
(
p
)
self
.
pegs
.
append
(
p
)
x1
,
x2
=
x1
+
pegdist
,
x2
+
pegdist
x1
,
x2
=
x1
+
pegdist
,
x2
+
pegdist
p
=
c
.
create_rectangle
(
x1
,
y1
,
x2
,
y2
,
{
'fill'
:
'black'
}
)
p
=
c
.
create_rectangle
(
x1
,
y1
,
x2
,
y2
,
fill
=
'black'
)
self
.
pegs
.
append
(
p
)
self
.
pegs
.
append
(
p
)
self
.
tk
.
update
()
self
.
tk
.
update
()
...
@@ -66,8 +66,7 @@ class Tkhanoi:
...
@@ -66,8 +66,7 @@ class Tkhanoi:
x2
,
y2
=
x1
+
maxpiecewidth
,
y1
+
pieceheight
x2
,
y2
=
x1
+
maxpiecewidth
,
y1
+
pieceheight
dx
=
(
maxpiecewidth
-
minpiecewidth
)
/
(
2
*
max
(
1
,
n
-
1
))
dx
=
(
maxpiecewidth
-
minpiecewidth
)
/
(
2
*
max
(
1
,
n
-
1
))
for
i
in
range
(
n
,
0
,
-
1
):
for
i
in
range
(
n
,
0
,
-
1
):
p
=
c
.
create_rectangle
(
x1
,
y1
,
x2
,
y2
,
p
=
c
.
create_rectangle
(
x1
,
y1
,
x2
,
y2
,
fill
=
'red'
)
{
'fill'
:
'red'
})
self
.
pieces
[
i
]
=
p
self
.
pieces
[
i
]
=
p
self
.
pegstate
[
0
].
append
(
i
)
self
.
pegstate
[
0
].
append
(
i
)
x1
,
x2
=
x1
+
dx
,
x2
-
dx
x1
,
x2
=
x1
+
dx
,
x2
-
dx
...
...
Demo/tkinter/guido/kill.py
View file @
21891d60
...
@@ -5,14 +5,14 @@ from Tkinter import *
...
@@ -5,14 +5,14 @@ from Tkinter import *
from
string
import
splitfields
from
string
import
splitfields
from
string
import
split
from
string
import
split
import
commands
import
commands
import
posix
import
os
class
BarButton
(
Menubutton
):
class
BarButton
(
Menubutton
):
_CNF
=
{
Pack
:
{
'side'
:
'left'
}}
def
__init__
(
self
,
master
=
None
,
**
cnf
):
def
__init__
(
self
,
master
=
None
,
cnf
=
{}):
apply
(
Menubutton
.
__init__
,
(
self
,
master
),
cnf
)
Menubutton
.
__init__
(
self
,
master
,
(
self
.
_CNF
,
cnf
)
)
self
.
pack
(
side
=
LEFT
)
self
.
menu
=
Menu
(
self
,
{
'name'
:
'menu'
}
)
self
.
menu
=
Menu
(
self
,
name
=
'menu'
)
self
[
'menu'
]
=
self
.
menu
self
[
'menu'
]
=
self
.
menu
class
Kill
(
Frame
):
class
Kill
(
Frame
):
# List of (name, option, pid_column)
# List of (name, option, pid_column)
...
@@ -27,7 +27,7 @@ class Kill(Frame):
...
@@ -27,7 +27,7 @@ class Kill(Frame):
def
kill
(
self
,
selected
):
def
kill
(
self
,
selected
):
c
=
self
.
format_list
[
self
.
format
.
get
()][
2
]
c
=
self
.
format_list
[
self
.
format
.
get
()][
2
]
pid
=
split
(
selected
)[
c
]
pid
=
split
(
selected
)[
c
]
posix
.
system
(
'kill'
+
'
-9 '
+
pid
)
os
.
system
(
'kill
-9 '
+
pid
)
self
.
do_update
()
self
.
do_update
()
def
do_update
(
self
):
def
do_update
(
self
):
name
,
option
,
column
=
self
.
format_list
[
self
.
format
.
get
()]
name
,
option
,
column
=
self
.
format_list
[
self
.
format
.
get
()]
...
@@ -35,85 +35,64 @@ class Kill(Frame):
...
@@ -35,85 +35,64 @@ class Kill(Frame):
list
=
splitfields
(
s
,
'
\
n
'
)
list
=
splitfields
(
s
,
'
\
n
'
)
self
.
header
.
set
(
list
[
0
])
self
.
header
.
set
(
list
[
0
])
del
list
[
0
]
del
list
[
0
]
y
=
self
.
frame
.
vscroll
.
get
()[
2
]
y
=
self
.
frame
.
vscroll
.
get
()[
0
]
self
.
frame
.
list
.
delete
(
0
,
AtEnd
())
self
.
frame
.
list
.
delete
(
0
,
AtEnd
())
for
line
in
list
:
for
line
in
list
:
self
.
frame
.
list
.
insert
(
0
,
line
)
self
.
frame
.
list
.
insert
(
0
,
line
)
self
.
frame
.
list
.
yview
(
y
)
self
.
frame
.
list
.
yview
(
int
(
y
)
)
def
do_motion
(
self
,
e
):
def
do_motion
(
self
,
e
):
e
.
widget
.
select_from
(
e
.
widget
.
nearest
(
e
.
y
))
e
.
widget
.
select_clear
(
0
,
END
)
e
.
widget
.
select_set
(
e
.
widget
.
nearest
(
e
.
y
))
def
do_leave
(
self
,
e
):
def
do_leave
(
self
,
e
):
e
.
widget
.
select_clear
()
e
.
widget
.
select_clear
(
0
,
END
)
def
do_1
(
self
,
e
):
def
do_1
(
self
,
e
):
self
.
kill
(
e
.
widget
.
get
(
e
.
widget
.
nearest
(
e
.
y
)))
self
.
kill
(
e
.
widget
.
get
(
e
.
widget
.
nearest
(
e
.
y
)))
def
__init__
(
self
,
master
=
None
,
cnf
=
{}
):
def
__init__
(
self
,
master
=
None
,
**
cnf
):
Frame
.
__init__
(
self
,
master
,
cnf
)
Frame
.
__init__
(
self
,
master
,
cnf
)
self
.
pack
({
'expand'
:
'yes'
,
'fill'
:
'both'
})
self
.
pack
(
expand
=
1
,
fill
=
BOTH
)
self
.
bar
=
Frame
(
self
.
bar
=
Frame
(
self
,
name
=
'bar'
,
relief
=
RAISED
,
self
,
borderwidth
=
2
)
{
'name'
:
'bar'
,
self
.
bar
.
pack
(
fill
=
X
)
'relief'
:
'raised'
,
self
.
bar
.
file
=
BarButton
(
self
.
bar
,
text
=
'File'
)
'bd'
:
2
,
Pack
:
{
'side'
:
'top'
,
'fill'
:
'x'
}})
self
.
bar
.
file
=
BarButton
(
self
.
bar
,
{
'text'
:
'File'
})
self
.
bar
.
file
.
menu
.
add_command
(
self
.
bar
.
file
.
menu
.
add_command
(
{
'label'
:
'Quit'
,
'command'
:
self
.
quit
}
)
label
=
'Quit'
,
command
=
self
.
quit
)
self
.
bar
.
view
=
BarButton
(
self
.
bar
,
{
'text'
:
'View'
}
)
self
.
bar
.
view
=
BarButton
(
self
.
bar
,
text
=
'View'
)
self
.
format
=
IntVar
(
self
)
self
.
format
=
IntVar
(
self
)
self
.
format
.
set
(
2
)
self
.
format
.
set
(
2
)
for
num
in
range
(
len
(
self
.
format_list
)):
for
num
in
range
(
len
(
self
.
format_list
)):
self
.
bar
.
view
.
menu
.
add_radiobutton
(
self
.
bar
.
view
.
menu
.
add_radiobutton
(
{
'label'
:
self
.
format_list
[
num
][
0
],
label
=
self
.
format_list
[
num
][
0
],
'command'
:
self
.
do_update
,
command
=
self
.
do_update
,
'variable'
:
self
.
format
,
variable
=
self
.
format
,
'value'
:
num
}
)
value
=
num
)
#self.bar.view.menu.add_separator()
#self.bar.view.menu.add_separator()
#XXX ...
#XXX ...
self
.
bar
.
tk_menuBar
(
self
.
bar
.
file
,
self
.
bar
.
view
)
self
.
bar
.
tk_menuBar
(
self
.
bar
.
file
,
self
.
bar
.
view
)
self
.
frame
=
Frame
(
self
.
frame
=
Frame
(
self
,
relief
=
RAISED
,
borderwidth
=
2
)
self
,
self
.
frame
.
pack
(
expand
=
1
,
fill
=
BOTH
)
{
'relief'
:
'raised'
,
'bd'
:
2
,
Pack
:
{
'side'
:
'top'
,
'expand'
:
'yes'
,
'fill'
:
'both'
}})
self
.
header
=
StringVar
(
self
)
self
.
header
=
StringVar
(
self
)
self
.
frame
.
label
=
Label
(
self
.
frame
.
label
=
Label
(
self
.
frame
,
relief
=
FLAT
,
anchor
=
NW
,
self
.
frame
,
borderwidth
=
0
,
{
'relief'
:
'flat'
,
textvariable
=
self
.
header
)
'anchor'
:
'nw'
,
self
.
frame
.
label
.
pack
(
fill
=
X
)
'borderwidth'
:
0
,
self
.
frame
.
vscroll
=
Scrollbar
(
self
.
frame
,
orient
=
VERTICAL
)
'textvariable'
:
self
.
header
,
self
.
frame
.
list
=
Listbox
(
self
.
frame
,
relief
=
SUNKEN
,
Pack
:
{
'side'
:
'top'
,
selectbackground
=
'#eed5b7'
,
'fill'
:
'x'
}})
selectborderwidth
=
0
,
self
.
frame
.
vscroll
=
Scrollbar
(
yscroll
=
self
.
frame
.
vscroll
.
set
)
self
.
frame
,
{
'orient'
:
'vertical'
})
self
.
frame
.
list
=
Listbox
(
self
.
frame
,
{
'relief'
:
'sunken'
,
'selectbackground'
:
'#eed5b7'
,
'selectborderwidth'
:
0
,
'yscroll'
:
self
.
frame
.
vscroll
.
set
})
self
.
frame
.
vscroll
[
'command'
]
=
self
.
frame
.
list
.
yview
self
.
frame
.
vscroll
[
'command'
]
=
self
.
frame
.
list
.
yview
self
.
frame
.
vscroll
.
pack
({
'side'
:
'right'
,
'fill'
:
'y'
})
self
.
frame
.
vscroll
.
pack
(
side
=
RIGHT
,
fill
=
Y
)
self
.
frame
.
list
.
pack
(
self
.
frame
.
list
.
pack
(
expand
=
1
,
fill
=
BOTH
)
{
'side'
:
'top'
,
self
.
update
=
Button
(
self
,
text
=
"Update"
,
'expand'
:
'yes'
,
command
=
self
.
do_update
)
'fill'
:
'both'
})
self
.
update
.
pack
(
expand
=
1
,
fill
=
X
)
self
.
update
=
Button
(
self
,
{
'text'
:
'Update'
,
'command'
:
self
.
do_update
,
Pack
:
{
'expand'
:
'yes'
,
'fill'
:
'x'
}})
self
.
frame
.
list
.
bind
(
'<Motion>'
,
self
.
do_motion
)
self
.
frame
.
list
.
bind
(
'<Motion>'
,
self
.
do_motion
)
self
.
frame
.
list
.
bind
(
'<Leave>'
,
self
.
do_leave
)
self
.
frame
.
list
.
bind
(
'<Leave>'
,
self
.
do_leave
)
self
.
frame
.
list
.
bind
(
'<1>'
,
self
.
do_1
)
self
.
frame
.
list
.
bind
(
'<1>'
,
self
.
do_1
)
self
.
do_update
()
self
.
do_update
()
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
kill
=
Kill
(
None
,
{
'bd'
:
5
}
)
kill
=
Kill
(
None
,
borderwidth
=
5
)
kill
.
winfo_toplevel
().
title
(
'Tkinter Process Killer'
)
kill
.
winfo_toplevel
().
title
(
'Tkinter Process Killer'
)
kill
.
winfo_toplevel
().
minsize
(
1
,
1
)
kill
.
winfo_toplevel
().
minsize
(
1
,
1
)
kill
.
mainloop
()
kill
.
mainloop
()
...
...
Demo/tkinter/guido/listtree.py
View file @
21891d60
...
@@ -6,16 +6,16 @@ import string
...
@@ -6,16 +6,16 @@ import string
from
Tkinter
import
*
from
Tkinter
import
*
def
listtree
(
master
,
app
):
def
listtree
(
master
,
app
):
list
=
Listbox
(
master
,
{
'name'
:
'list'
,
list
=
Listbox
(
master
,
name
=
'list'
)
Pack
:
{
'expand'
:
1
,
'fill'
:
'both'
}}
)
list
.
pack
(
expand
=
1
,
fill
=
BOTH
)
listnodes
(
list
,
app
,
'.'
,
0
)
listnodes
(
list
,
app
,
'.'
,
0
)
return
list
return
list
def
listnodes
(
list
,
app
,
widget
,
level
):
def
listnodes
(
list
,
app
,
widget
,
level
):
klass
=
list
.
send
(
app
,
'winfo'
,
'class'
,
widget
)
klass
=
list
.
send
(
app
,
'winfo'
,
'class'
,
widget
)
## i = string.rindex(widget, '.')
## i = string.rindex(widget, '.')
## list.insert(
'end'
, '%s%s (%s)' % ((level-1)*'. ', widget[i:], klass))
## list.insert(
END
, '%s%s (%s)' % ((level-1)*'. ', widget[i:], klass))
list
.
insert
(
'end'
,
'%s (%s)'
%
(
widget
,
klass
))
list
.
insert
(
END
,
'%s (%s)'
%
(
widget
,
klass
))
children
=
list
.
tk
.
splitlist
(
children
=
list
.
tk
.
splitlist
(
list
.
send
(
app
,
'winfo'
,
'children'
,
widget
))
list
.
send
(
app
,
'winfo'
,
'children'
,
widget
))
for
c
in
children
:
for
c
in
children
:
...
@@ -28,7 +28,8 @@ def main():
...
@@ -28,7 +28,8 @@ def main():
app
=
sys
.
argv
[
1
]
app
=
sys
.
argv
[
1
]
tk
=
Tk
()
tk
=
Tk
()
tk
.
minsize
(
1
,
1
)
tk
.
minsize
(
1
,
1
)
f
=
Frame
(
tk
,
{
'name'
:
'f'
,
Pack
:
{
'expand'
:
1
,
'fill'
:
'both'
}})
f
=
Frame
(
tk
,
name
=
'f'
)
f
.
pack
(
expand
=
1
,
fill
=
BOTH
)
list
=
listtree
(
f
,
app
)
list
=
listtree
(
f
,
app
)
tk
.
mainloop
()
tk
.
mainloop
()
...
...
Demo/tkinter/guido/svkill.py
View file @
21891d60
...
@@ -15,10 +15,10 @@ import os
...
@@ -15,10 +15,10 @@ import os
user
=
os
.
environ
[
'LOGNAME'
]
user
=
os
.
environ
[
'LOGNAME'
]
class
BarButton
(
Menubutton
):
class
BarButton
(
Menubutton
):
def
__init__
(
self
,
master
=
None
,
cnf
=
{}
):
def
__init__
(
self
,
master
=
None
,
**
cnf
):
Menubutton
.
__init__
(
self
,
master
,
cnf
)
apply
(
Menubutton
.
__init__
,
(
self
,
master
)
,
cnf
)
self
.
pack
(
side
=
'left'
)
self
.
pack
(
side
=
LEFT
)
self
.
menu
=
Menu
(
self
,
{
'name'
:
'menu'
}
)
self
.
menu
=
Menu
(
self
,
name
=
'menu'
)
self
[
'menu'
]
=
self
.
menu
self
[
'menu'
]
=
self
.
menu
class
Kill
(
Frame
):
class
Kill
(
Frame
):
...
@@ -41,7 +41,7 @@ class Kill(Frame):
...
@@ -41,7 +41,7 @@ class Kill(Frame):
def
kill
(
self
,
selected
):
def
kill
(
self
,
selected
):
c
=
self
.
format_list
[
self
.
format
.
get
()][
2
]
c
=
self
.
format_list
[
self
.
format
.
get
()][
2
]
pid
=
split
(
selected
)[
c
]
pid
=
split
(
selected
)[
c
]
os
.
system
(
'kill
'
+
'
-9 '
+
pid
)
os
.
system
(
'kill -9 '
+
pid
)
self
.
do_update
()
self
.
do_update
()
def
do_update
(
self
):
def
do_update
(
self
):
format
=
self
.
format_list
[
self
.
format
.
get
()][
1
]
format
=
self
.
format_list
[
self
.
format
.
get
()][
1
]
...
@@ -60,21 +60,17 @@ class Kill(Frame):
...
@@ -60,21 +60,17 @@ class Kill(Frame):
e
.
widget
.
select_clear
(
'0'
,
'end'
)
e
.
widget
.
select_clear
(
'0'
,
'end'
)
def
do_1
(
self
,
e
):
def
do_1
(
self
,
e
):
self
.
kill
(
e
.
widget
.
get
(
e
.
widget
.
nearest
(
e
.
y
)))
self
.
kill
(
e
.
widget
.
get
(
e
.
widget
.
nearest
(
e
.
y
)))
def
__init__
(
self
,
master
=
None
,
cnf
=
{}):
def
__init__
(
self
,
master
=
None
,
**
cnf
):
Frame
.
__init__
(
self
,
master
,
cnf
)
apply
(
Frame
.
__init__
,
(
self
,
master
),
cnf
)
self
.
pack
({
'expand'
:
'yes'
,
'fill'
:
'both'
})
self
.
pack
(
expand
=
1
,
fill
=
BOTH
)
self
.
bar
=
Frame
(
self
.
bar
=
Frame
(
self
,
name
=
'bar'
,
relief
=
RAISED
,
self
,
borderwidth
=
2
)
{
'name'
:
'bar'
,
self
.
bar
.
pack
(
fill
=
X
)
'relief'
:
'raised'
,
self
.
bar
.
file
=
BarButton
(
self
.
bar
,
text
=
'File'
)
'bd'
:
2
,
Pack
:
{
'side'
:
'top'
,
'fill'
:
'x'
}})
self
.
bar
.
file
=
BarButton
(
self
.
bar
,
{
'text'
:
'File'
})
self
.
bar
.
file
.
menu
.
add_command
(
self
.
bar
.
file
.
menu
.
add_command
(
{
'label'
:
'Quit'
,
'command'
:
self
.
quit
}
)
label
=
'Quit'
,
command
=
self
.
quit
)
self
.
bar
.
view
=
BarButton
(
self
.
bar
,
{
'text'
:
'View'
}
)
self
.
bar
.
view
=
BarButton
(
self
.
bar
,
text
=
'View'
)
self
.
bar
.
format
=
BarButton
(
self
.
bar
,
{
'text'
:
'Format'
}
)
self
.
bar
.
format
=
BarButton
(
self
.
bar
,
text
=
'Format'
)
self
.
view
=
IntVar
(
self
)
self
.
view
=
IntVar
(
self
)
self
.
view
.
set
(
0
)
self
.
view
.
set
(
0
)
self
.
format
=
IntVar
(
self
)
self
.
format
=
IntVar
(
self
)
...
@@ -82,68 +78,51 @@ class Kill(Frame):
...
@@ -82,68 +78,51 @@ class Kill(Frame):
for
num
in
range
(
len
(
self
.
view_list
)):
for
num
in
range
(
len
(
self
.
view_list
)):
label
,
option
=
self
.
view_list
[
num
]
label
,
option
=
self
.
view_list
[
num
]
self
.
bar
.
view
.
menu
.
add_radiobutton
(
self
.
bar
.
view
.
menu
.
add_radiobutton
(
{
'label'
:
label
,
label
=
label
,
'command'
:
self
.
do_update
,
command
=
self
.
do_update
,
'variable'
:
self
.
view
,
variable
=
self
.
view
,
'value'
:
num
}
)
value
=
num
)
for
num
in
range
(
len
(
self
.
format_list
)):
for
num
in
range
(
len
(
self
.
format_list
)):
label
,
option
,
col
=
self
.
format_list
[
num
]
label
,
option
,
col
=
self
.
format_list
[
num
]
self
.
bar
.
format
.
menu
.
add_radiobutton
(
self
.
bar
.
format
.
menu
.
add_radiobutton
(
{
'label'
:
label
,
label
=
label
,
'command'
:
self
.
do_update
,
command
=
self
.
do_update
,
'variable'
:
self
.
format
,
variable
=
self
.
format
,
'value'
:
num
}
)
value
=
num
)
self
.
bar
.
tk_menuBar
(
self
.
bar
.
file
,
self
.
bar
.
tk_menuBar
(
self
.
bar
.
file
,
self
.
bar
.
view
,
self
.
bar
.
view
,
self
.
bar
.
format
)
self
.
bar
.
format
)
self
.
frame
=
Frame
(
self
.
frame
=
Frame
(
self
,
relief
=
RAISED
,
borderwidth
=
2
)
self
,
self
.
frame
.
pack
(
expand
=
1
,
fill
=
BOTH
)
{
'relief'
:
'raised'
,
'bd'
:
2
,
Pack
:
{
'side'
:
'top'
,
'expand'
:
'yes'
,
'fill'
:
'both'
}})
self
.
header
=
StringVar
(
self
)
self
.
header
=
StringVar
(
self
)
self
.
frame
.
label
=
Label
(
self
.
frame
.
label
=
Label
(
self
.
frame
,
self
.
frame
,
relief
=
FLAT
,
anchor
=
NW
,
borderwidth
=
0
,
{
'relief'
:
'flat'
,
font
=
'*-Courier-Bold-R-Normal-*-120-*'
,
'anchor'
:
'nw'
,
textvariable
=
self
.
header
)
'borderwidth'
:
0
,
self
.
frame
.
label
.
pack
(
fill
=
Y
,
anchor
=
W
)
'font'
:
'*-Courier-Bold-R-Normal-*-120-*'
,
self
.
frame
.
vscroll
=
Scrollbar
(
self
.
frame
,
orient
=
VERTICAL
)
'textvariable'
:
self
.
header
,
Pack
:
{
'side'
:
'top'
,
'fill'
:
'y'
,
'anchor'
:
'w'
}})
self
.
frame
.
vscroll
=
Scrollbar
(
self
.
frame
,
{
'orient'
:
'vertical'
})
self
.
frame
.
list
=
Listbox
(
self
.
frame
.
list
=
Listbox
(
self
.
frame
,
self
.
frame
,
{
'relief'
:
'sunken'
,
relief
=
SUNKEN
,
'font'
:
'*-Courier-Medium-R-Normal-*-120-*'
,
font
=
'*-Courier-Medium-R-Normal-*-120-*'
,
'width'
:
40
,
'height'
:
10
,
width
=
40
,
height
=
10
,
'selectbackground'
:
'#eed5b7'
,
selectbackground
=
'#eed5b7'
,
'selectborderwidth'
:
0
,
selectborderwidth
=
0
,
'selectmode'
:
'browse'
,
selectmode
=
BROWSE
,
'yscroll'
:
self
.
frame
.
vscroll
.
set
}
)
yscroll
=
self
.
frame
.
vscroll
.
set
)
self
.
frame
.
vscroll
[
'command'
]
=
self
.
frame
.
list
.
yview
self
.
frame
.
vscroll
[
'command'
]
=
self
.
frame
.
list
.
yview
self
.
frame
.
vscroll
.
pack
({
'side'
:
'right'
,
'fill'
:
'y'
})
self
.
frame
.
vscroll
.
pack
(
side
=
RIGHT
,
fill
=
Y
)
self
.
frame
.
list
.
pack
(
self
.
frame
.
list
.
pack
(
expand
=
1
,
fill
=
BOTH
)
{
'side'
:
'top'
,
self
.
update
=
Button
(
self
,
text
=
'Update'
,
'expand'
:
'yes'
,
command
=
self
.
do_update
)
'fill'
:
'both'
})
self
.
update
.
pack
(
fill
=
X
)
self
.
update
=
Button
(
self
,
{
'text'
:
'Update'
,
'command'
:
self
.
do_update
,
Pack
:
{
'expand'
:
'no'
,
'fill'
:
'x'
}})
self
.
frame
.
list
.
bind
(
'<Motion>'
,
self
.
do_motion
)
self
.
frame
.
list
.
bind
(
'<Motion>'
,
self
.
do_motion
)
self
.
frame
.
list
.
bind
(
'<Leave>'
,
self
.
do_leave
)
self
.
frame
.
list
.
bind
(
'<Leave>'
,
self
.
do_leave
)
self
.
frame
.
list
.
bind
(
'<1>'
,
self
.
do_1
)
self
.
frame
.
list
.
bind
(
'<1>'
,
self
.
do_1
)
self
.
do_update
()
self
.
do_update
()
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
kill
=
Kill
(
None
,
{
'bd'
:
5
}
)
kill
=
Kill
(
None
,
borderwidth
=
5
)
kill
.
winfo_toplevel
().
title
(
'Tkinter Process Killer (SYSV)'
)
kill
.
winfo_toplevel
().
title
(
'Tkinter Process Killer (SYSV)'
)
kill
.
winfo_toplevel
().
minsize
(
1
,
1
)
kill
.
winfo_toplevel
().
minsize
(
1
,
1
)
kill
.
mainloop
()
kill
.
mainloop
()
Demo/tkinter/guido/tkman.py
View file @
21891d60
#! /home/guido/bin.sgi/python
#! /usr/local/bin/python
#! /usr/local/bin/python
# Tk man page browser -- currently only shows the Tcl/Tk man pages
# Tk man page browser -- currently only shows the Tcl/Tk man pages
...
@@ -32,81 +31,66 @@ class SelectionBox:
...
@@ -32,81 +31,66 @@ class SelectionBox:
def
__init__
(
self
,
master
=
None
):
def
__init__
(
self
,
master
=
None
):
self
.
choices
=
[]
self
.
choices
=
[]
self
.
frame
=
Frame
(
master
,
{
self
.
frame
=
Frame
(
master
,
name
=
"frame"
)
'name'
:
'frame'
,
self
.
frame
.
pack
(
expand
=
1
,
fill
=
BOTH
)
Pack
:
{
'expand'
:
1
,
'fill'
:
'both'
}})
self
.
master
=
self
.
frame
.
master
self
.
master
=
self
.
frame
.
master
self
.
subframe
=
Frame
(
self
.
frame
,
{
self
.
subframe
=
Frame
(
self
.
frame
,
name
=
"subframe"
)
'name'
:
'subframe'
,
self
.
subframe
.
pack
(
expand
=
0
,
fill
=
BOTH
)
Pack
:
{
'expand'
:
0
,
'fill'
:
'both'
}})
self
.
leftsubframe
=
Frame
(
self
.
subframe
,
name
=
'leftsubframe'
)
self
.
leftsubframe
=
Frame
(
self
.
subframe
,
{
self
.
leftsubframe
.
pack
(
side
=
LEFT
,
expand
=
1
,
fill
=
BOTH
)
'name'
:
'leftsubframe'
,
self
.
rightsubframe
=
Frame
(
self
.
subframe
,
name
=
'rightsubframe'
)
Pack
:
{
'side'
:
'left'
,
'expand'
:
1
,
'fill'
:
'both'
}})
self
.
rightsubframe
.
pack
(
side
=
RIGHT
,
expand
=
1
,
fill
=
BOTH
)
self
.
rightsubframe
=
Frame
(
self
.
subframe
,
{
'name'
:
'rightsubframe'
,
Pack
:
{
'side'
:
'right'
,
'expand'
:
1
,
'fill'
:
'both'
}})
self
.
chaptervar
=
StringVar
(
master
)
self
.
chaptervar
=
StringVar
(
master
)
self
.
chapter
=
Menubutton
(
self
.
rightsubframe
,
self
.
chapter
=
Menubutton
(
self
.
rightsubframe
,
name
=
'chapter'
,
{
'name'
:
'chapter'
,
text
=
'Directory'
,
relief
=
RAISED
,
'text'
:
'Directory'
,
borderwidth
=
2
)
'relief'
:
'raised'
,
'bd'
:
2
,
self
.
chapter
.
pack
(
side
=
TOP
)
Pack
:
{
'side'
:
'top'
}})
self
.
chaptermenu
=
Menu
(
self
.
chapter
,
name
=
'chaptermenu'
)
self
.
chaptermenu
=
Menu
(
self
.
chapter
,
{
'name'
:
'chaptermenu'
})
self
.
chaptermenu
.
add_radiobutton
(
label
=
'C functions'
,
self
.
chaptermenu
.
add_radiobutton
({
'label'
:
'C functions'
,
value
=
MAN3DIR
,
'value'
:
MAN3DIR
,
variable
=
self
.
chaptervar
,
'variable'
:
self
.
chaptervar
,
command
=
self
.
newchapter
)
'command'
:
self
.
newchapter
})
self
.
chaptermenu
.
add_radiobutton
(
label
=
'Tcl/Tk functions'
,
self
.
chaptermenu
.
add_radiobutton
({
'label'
:
'Tcl/Tk functions'
,
value
=
MANNDIR
,
'value'
:
MANNDIR
,
variable
=
self
.
chaptervar
,
'variable'
:
self
.
chaptervar
,
command
=
self
.
newchapter
)
'command'
:
self
.
newchapter
})
self
.
chapter
[
'menu'
]
=
self
.
chaptermenu
self
.
chapter
[
'menu'
]
=
self
.
chaptermenu
self
.
listbox
=
Listbox
(
self
.
rightsubframe
,
self
.
listbox
=
Listbox
(
self
.
rightsubframe
,
name
=
'listbox'
,
{
'name'
:
'listbox'
,
relief
=
SUNKEN
,
borderwidth
=
2
,
'relief'
:
'sunken'
,
'bd'
:
2
,
width
=
20
,
height
=
5
)
'width'
:
20
,
'height'
:
5
,
self
.
listbox
.
pack
(
expand
=
1
,
fill
=
BOTH
)
Pack
:
{
'expand'
:
1
,
'fill'
:
'both'
}})
self
.
l1
=
Button
(
self
.
leftsubframe
,
name
=
'l1'
,
self
.
l1
=
Button
(
self
.
leftsubframe
,
text
=
'Display manual page named:'
,
{
'name'
:
'l1'
,
command
=
self
.
entry_cb
)
'text'
:
'Display manual page named:'
,
self
.
l1
.
pack
(
side
=
TOP
)
'command'
:
self
.
entry_cb
,
self
.
entry
=
Entry
(
self
.
leftsubframe
,
name
=
'entry'
,
Pack
:
{
'side'
:
'top'
}})
relief
=
SUNKEN
,
borderwidth
=
2
,
self
.
entry
=
Entry
(
self
.
leftsubframe
,
width
=
20
)
{
'name'
:
'entry'
,
self
.
entry
.
pack
(
expand
=
0
,
fill
=
X
)
'relief'
:
'sunken'
,
'bd'
:
2
,
self
.
l2frame
=
Frame
(
self
.
leftsubframe
,
name
=
'l2frame'
)
'width'
:
20
,
self
.
l2frame
.
pack
(
expand
=
0
,
fill
=
NONE
)
Pack
:
{
'side'
:
'top'
,
self
.
l2
=
Button
(
self
.
l2frame
,
name
=
'l2'
,
'expand'
:
0
,
'fill'
:
'x'
}})
text
=
'Search regexp:'
,
self
.
l2frame
=
Frame
(
self
.
leftsubframe
,
command
=
self
.
search_cb
)
{
'name'
:
'l2frame'
,
self
.
l2
.
pack
(
side
=
LEFT
)
Pack
:
{
'expand'
:
0
,
'fill'
:
'none'
}})
self
.
casevar
=
BooleanVar
()
self
.
l2
=
Button
(
self
.
l2frame
,
self
.
casesense
=
Checkbutton
(
self
.
l2frame
,
name
=
'casesense'
,
{
'name'
:
'l2'
,
text
=
'Case sensitive'
,
'text'
:
'Search regexp:'
,
variable
=
self
.
casevar
,
'command'
:
self
.
search_cb
,
relief
=
FLAT
)
Pack
:
{
'side'
:
'left'
}})
self
.
casesense
.
pack
(
side
=
LEFT
)
self
.
casesense
=
Checkbutton
(
self
.
l2frame
,
self
.
search
=
Entry
(
self
.
leftsubframe
,
name
=
'search'
,
{
'name'
:
'casesense'
,
relief
=
SUNKEN
,
borderwidth
=
2
,
'text'
:
'Case sensitive'
,
width
=
20
)
'variable'
:
'casesense'
,
self
.
search
.
pack
(
expand
=
0
,
fill
=
X
)
'relief'
:
'flat'
,
self
.
title
=
Label
(
self
.
leftsubframe
,
name
=
'title'
,
Pack
:
{
'side'
:
'left'
}})
text
=
'(none)'
)
self
.
search
=
Entry
(
self
.
leftsubframe
,
self
.
title
.
pack
(
side
=
BOTTOM
)
{
'name'
:
'search'
,
self
.
text
=
ManPage
(
self
.
frame
,
name
=
'text'
,
'relief'
:
'sunken'
,
'bd'
:
2
,
relief
=
SUNKEN
,
borderwidth
=
2
,
'width'
:
20
,
wrap
=
NONE
,
width
=
72
,
Pack
:
{
'side'
:
'top'
,
selectbackground
=
'pink'
)
'expand'
:
0
,
'fill'
:
'x'
}})
self
.
text
.
pack
(
expand
=
1
,
fill
=
BOTH
)
self
.
title
=
Label
(
self
.
leftsubframe
,
{
'name'
:
'title'
,
'text'
:
'(none)'
,
Pack
:
{
'side'
:
'bottom'
}})
self
.
text
=
ManPage
(
self
.
frame
,
{
'name'
:
'text'
,
'relief'
:
'sunken'
,
'bd'
:
2
,
'wrap'
:
'none'
,
'width'
:
72
,
'selectbackground'
:
'pink'
,
Pack
:
{
'expand'
:
1
,
'fill'
:
'both'
}})
self
.
entry
.
bind
(
'<Return>'
,
self
.
entry_cb
)
self
.
entry
.
bind
(
'<Return>'
,
self
.
entry_cb
)
self
.
search
.
bind
(
'<Return>'
,
self
.
search_cb
)
self
.
search
.
bind
(
'<Return>'
,
self
.
search_cb
)
...
@@ -195,7 +179,7 @@ class SelectionBox:
...
@@ -195,7 +179,7 @@ class SelectionBox:
self
.
frame
.
bell
()
self
.
frame
.
bell
()
print
'Empty search string'
print
'Empty search string'
return
return
if
self
.
frame
.
tk
.
getvar
(
'casesense'
)
!=
'1'
:
if
not
self
.
casevar
.
get
()
:
map
=
regex
.
casefold
map
=
regex
.
casefold
else
:
else
:
map
=
None
map
=
None
...
...
Demo/tkinter/matt/00-HELLO-WORLD.py
View file @
21891d60
...
@@ -8,18 +8,15 @@ class Test(Frame):
...
@@ -8,18 +8,15 @@ class Test(Frame):
print
"hi"
print
"hi"
def
createWidgets
(
self
):
def
createWidgets
(
self
):
self
.
QUIT
=
Button
(
self
,
{
'text'
:
'QUIT'
,
self
.
QUIT
=
Button
(
self
,
text
=
'QUIT'
,
foreground
=
'red'
,
'fg'
:
'red'
,
command
=
self
.
quit
)
'command'
:
self
.
quit
})
self
.
QUIT
.
pack
({
'side'
:
'left'
,
'fill'
:
'both'
})
self
.
QUIT
.
pack
(
side
=
LEFT
,
fill
=
BOTH
)
# a hello button
# a hello button
self
.
hi_there
=
Button
(
self
,
{
'text'
:
'Hello'
,
self
.
hi_there
=
Button
(
self
,
text
=
'Hello'
,
'command'
:
self
.
printit
})
command
=
self
.
printit
)
self
.
hi_there
.
pack
({
'side'
:
'left'
})
self
.
hi_there
.
pack
(
side
=
LEFT
)
def
__init__
(
self
,
master
=
None
):
def
__init__
(
self
,
master
=
None
):
Frame
.
__init__
(
self
,
master
)
Frame
.
__init__
(
self
,
master
)
...
...
Demo/tkinter/matt/animation-simple.py
View file @
21891d60
...
@@ -7,16 +7,15 @@ class Test(Frame):
...
@@ -7,16 +7,15 @@ class Test(Frame):
print
"hi"
print
"hi"
def
createWidgets
(
self
):
def
createWidgets
(
self
):
self
.
QUIT
=
Button
(
self
,
{
'text'
:
'QUIT'
,
self
.
QUIT
=
Button
(
self
,
text
=
'QUIT'
,
foreground
=
'red'
,
'fg'
:
'red'
,
command
=
self
.
quit
)
'command'
:
self
.
quit
})
self
.
QUIT
.
pack
(
side
=
LEFT
,
fill
=
BOTH
)
self
.
QUIT
.
pack
({
'side'
:
'left'
,
'fill'
:
'both'
})
self
.
draw
=
Canvas
(
self
,
{
"width"
:
"5i"
,
"height"
:
"5i"
}
)
self
.
draw
=
Canvas
(
self
,
width
=
"5i"
,
height
=
"5i"
)
# all of these work..
# all of these work..
self
.
draw
.
create_
polygon
(
"0"
,
"0"
,
"10"
,
"0"
,
"10"
,
"10"
,
"0"
,
"10"
,
{
"tags"
:
"thing"
}
)
self
.
draw
.
create_
rectangle
(
0
,
0
,
10
,
10
,
tags
=
"thing"
,
fill
=
"blue"
)
self
.
draw
.
pack
(
{
'side'
:
'left'
}
)
self
.
draw
.
pack
(
side
=
LEFT
)
def
moveThing
(
self
,
*
args
):
def
moveThing
(
self
,
*
args
):
# move 1/10 of an inch every 1/10 sec (1" per second, smoothly)
# move 1/10 of an inch every 1/10 sec (1" per second, smoothly)
...
...
Demo/tkinter/matt/animation-w-velocity-ctrl.py
View file @
21891d60
...
@@ -6,29 +6,24 @@ from Tkinter import *
...
@@ -6,29 +6,24 @@ from Tkinter import *
# Tkinter is smart enough to start the system if it's not already going.
# Tkinter is smart enough to start the system if it's not already going.
class
Test
(
Frame
):
class
Test
(
Frame
):
def
printit
(
self
):
def
printit
(
self
):
print
"hi"
print
"hi"
def
createWidgets
(
self
):
def
createWidgets
(
self
):
self
.
QUIT
=
Button
(
self
,
{
'text'
:
'QUIT'
,
self
.
QUIT
=
Button
(
self
,
text
=
'QUIT'
,
foreground
=
'red'
,
'fg'
:
'red'
,
command
=
self
.
quit
)
'command'
:
self
.
quit
})
self
.
QUIT
.
pack
(
side
=
BOTTOM
,
fill
=
BOTH
)
self
.
QUIT
.
pack
({
'side'
:
'bottom'
,
'fill'
:
'both'
})
self
.
draw
=
Canvas
(
self
,
{
"width"
:
"5i"
,
"height"
:
"5i"
}
)
self
.
draw
=
Canvas
(
self
,
width
=
"5i"
,
height
=
"5i"
)
self
.
speed
=
Scale
(
self
,
{
"orient"
:
"horiz"
,
self
.
speed
=
Scale
(
self
,
orient
=
HORIZONTAL
,
from_
=-
100
,
to
=
100
)
"from"
:
-
100
,
"to"
:
100
})
self
.
speed
.
pack
(
{
'side'
:
'bottom'
,
"fill"
:
"x"
}
)
self
.
speed
.
pack
(
side
=
BOTTOM
,
fill
=
X
)
# all of these work..
# all of these work..
self
.
draw
.
create_
polygon
(
"0"
,
"0"
,
"10"
,
"0"
,
"10"
,
"10"
,
"0"
,
"10"
,
{
"tags"
:
"thing"
}
)
self
.
draw
.
create_
rectangle
(
0
,
0
,
10
,
10
,
tags
=
"thing"
,
fill
=
"blue"
)
self
.
draw
.
pack
(
{
'side'
:
'left'
}
)
self
.
draw
.
pack
(
side
=
LEFT
)
def
moveThing
(
self
,
*
args
):
def
moveThing
(
self
,
*
args
):
velocity
=
self
.
speed
.
get
()
velocity
=
self
.
speed
.
get
()
...
@@ -37,8 +32,6 @@ class Test(Frame):
...
@@ -37,8 +32,6 @@ class Test(Frame):
self
.
draw
.
move
(
"thing"
,
str
,
str
)
self
.
draw
.
move
(
"thing"
,
str
,
str
)
self
.
after
(
10
,
self
.
moveThing
)
self
.
after
(
10
,
self
.
moveThing
)
def
__init__
(
self
,
master
=
None
):
def
__init__
(
self
,
master
=
None
):
Frame
.
__init__
(
self
,
master
)
Frame
.
__init__
(
self
,
master
)
Pack
.
config
(
self
)
Pack
.
config
(
self
)
...
...
Demo/tkinter/matt/bind-w-mult-calls-p-type.py
View file @
21891d60
...
@@ -18,8 +18,9 @@ class App(Frame):
...
@@ -18,8 +18,9 @@ class App(Frame):
# Note that here is where we bind a completely different callback to
# Note that here is where we bind a completely different callback to
# the same event. We pass "+" here to indicate that we wish to ADD
# the same event. We pass "+" here to indicate that we wish to ADD
# this callback to the list associated with this event type. Not specifying "+" would
# this callback to the list associated with this event type.
# simply override whatever callback was defined on this event.
# Not specifying "+" would simply override whatever callback was
# defined on this event.
self
.
entrythingy
.
bind
(
'<Key-Return>'
,
self
.
print_something_else
,
"+"
)
self
.
entrythingy
.
bind
(
'<Key-Return>'
,
self
.
print_something_else
,
"+"
)
def
print_contents
(
self
,
event
):
def
print_contents
(
self
,
event
):
...
...
Demo/tkinter/matt/canvas-demo-simple.py
View file @
21891d60
...
@@ -7,18 +7,16 @@ class Test(Frame):
...
@@ -7,18 +7,16 @@ class Test(Frame):
print
"hi"
print
"hi"
def
createWidgets
(
self
):
def
createWidgets
(
self
):
self
.
QUIT
=
Button
(
self
,
{
'text'
:
'QUIT'
,
self
.
QUIT
=
Button
(
self
,
text
=
'QUIT'
,
foreground
=
'red'
,
'fg'
:
'red'
,
command
=
self
.
quit
)
'command'
:
self
.
quit
})
self
.
QUIT
.
pack
(
side
=
BOTTOM
,
fill
=
BOTH
)
self
.
QUIT
.
pack
({
'side'
:
'bottom'
,
'fill'
:
'both'
})
self
.
draw
=
Canvas
(
self
,
{
"width"
:
"5i"
,
"height"
:
"5i"
}
)
self
.
draw
=
Canvas
(
self
,
width
=
"5i"
,
height
=
"5i"
)
# see the other demos for other ways of specifying coords for a polygon
# see the other demos for other ways of specifying coords for a polygon
self
.
draw
.
create_polygon
(
"0i"
,
"0i"
,
"3i"
,
"0i"
,
"3i"
,
"3i"
,
"0i"
,
"3i"
)
self
.
draw
.
create_rectangle
(
0
,
0
,
"3i"
,
"3i"
,
fill
=
"black"
)
self
.
draw
.
pack
({
'side'
:
'left'
})
self
.
draw
.
pack
(
side
=
LEFT
)
def
__init__
(
self
,
master
=
None
):
def
__init__
(
self
,
master
=
None
):
Frame
.
__init__
(
self
,
master
)
Frame
.
__init__
(
self
,
master
)
...
...
Demo/tkinter/matt/canvas-gridding.py
View file @
21891d60
...
@@ -10,15 +10,15 @@ class Test(Frame):
...
@@ -10,15 +10,15 @@ class Test(Frame):
print
"hi"
print
"hi"
def
createWidgets
(
self
):
def
createWidgets
(
self
):
self
.
QUIT
=
Button
(
self
,
{
'text'
:
'QUIT'
,
self
.
QUIT
=
Button
(
self
,
text
=
'QUIT'
,
'bg'
:
'red'
,
background
=
'red'
,
'fg'
:
'white'
,
foreground
=
'white'
,
'height'
:
3
,
height
=
3
,
'command'
:
self
.
quit
}
)
command
=
self
.
quit
)
self
.
QUIT
.
pack
(
{
'side'
:
'bottom'
,
'fill'
:
'both'
}
)
self
.
QUIT
.
pack
(
side
=
BOTTOM
,
fill
=
BOTH
)
self
.
canvasObject
=
Canvas
(
self
,
{
"width"
:
"5i"
,
"height"
:
"5i"
}
)
self
.
canvasObject
=
Canvas
(
self
,
width
=
"5i"
,
height
=
"5i"
)
self
.
canvasObject
.
pack
(
{
'side'
:
'left'
}
)
self
.
canvasObject
.
pack
(
side
=
LEFT
)
def
mouseDown
(
self
,
event
):
def
mouseDown
(
self
,
event
):
# canvas x and y take the screen coords from the event and translate
# canvas x and y take the screen coords from the event and translate
...
@@ -29,12 +29,13 @@ class Test(Frame):
...
@@ -29,12 +29,13 @@ class Test(Frame):
def
mouseMotion
(
self
,
event
):
def
mouseMotion
(
self
,
event
):
# canvas x and y take the screen coords from the event and translate
# canvas x and y take the screen coords from the event and translate
# them into the coordinate system of the canvas object
# them into the coordinate system of the canvas object
x
=
self
.
canvasObject
.
canvasx
(
event
.
x
,
self
.
gridding
s
ize
)
x
=
self
.
canvasObject
.
canvasx
(
event
.
x
,
self
.
gridding
S
ize
)
y
=
self
.
canvasObject
.
canvasy
(
event
.
y
,
self
.
gridding
s
ize
)
y
=
self
.
canvasObject
.
canvasy
(
event
.
y
,
self
.
gridding
S
ize
)
if
(
self
.
startx
!=
event
.
x
)
and
(
self
.
starty
!=
event
.
y
)
:
if
(
self
.
startx
!=
event
.
x
)
and
(
self
.
starty
!=
event
.
y
)
:
self
.
canvasObject
.
delete
(
self
.
rubberbandBox
)
self
.
canvasObject
.
delete
(
self
.
rubberbandBox
)
self
.
rubberbandBox
=
self
.
canvasObject
.
create_rectangle
(
self
.
startx
,
self
.
starty
,
x
,
y
)
self
.
rubberbandBox
=
self
.
canvasObject
.
create_rectangle
(
self
.
startx
,
self
.
starty
,
x
,
y
)
# this flushes the output, making sure that
# this flushes the output, making sure that
# the rectangle makes it to the screen
# the rectangle makes it to the screen
# before the next event is handled
# before the next event is handled
...
...
Demo/tkinter/matt/canvas-moving-or-creating.py
View file @
21891d60
...
@@ -9,26 +9,24 @@ class Test(Frame):
...
@@ -9,26 +9,24 @@ class Test(Frame):
###################################################################
###################################################################
def
mouseDown
(
self
,
event
):
def
mouseDown
(
self
,
event
):
# see if we're inside a dot. If we are, it
# see if we're inside a dot. If we are, it
# gets tagged as "current" for free by tk.
# gets tagged as CURRENT for free by tk.
if
not
event
.
widget
.
find_withtag
(
CURRENT
):
if
not
event
.
widget
.
find_withtag
(
"current"
):
# there is no dot here, so we can make one,
# there is no dot here, so we can make one,
# and bind some interesting behavior to it.
# and bind some interesting behavior to it.
# ------
# ------
# create a dot, and mark it as CURRENT
# create a dot, and mark it as current
fred
=
self
.
draw
.
create_oval
(
fred
=
self
.
draw
.
create_oval
(
event
.
x
-
10
,
event
.
y
-
10
,
event
.
x
+
10
,
event
.
y
+
10
,
event
.
x
-
10
,
event
.
y
-
10
,
event
.
x
+
10
,
event
.
y
+
10
,
{
"fill"
:
"green"
,
"tag"
:
"current"
}
)
fill
=
"green"
,
tags
=
CURRENT
)
self
.
draw
.
bind
(
fred
,
"<Any-Enter>"
,
self
.
mouseEnter
)
self
.
draw
.
bind
(
fred
,
"<Any-Enter>"
,
self
.
mouseEnter
)
self
.
draw
.
bind
(
fred
,
"<Any-Leave>"
,
self
.
mouseLeave
)
self
.
draw
.
bind
(
fred
,
"<Any-Leave>"
,
self
.
mouseLeave
)
self
.
lastx
=
event
.
x
self
.
lastx
=
event
.
x
self
.
lasty
=
event
.
y
self
.
lasty
=
event
.
y
def
mouseMove
(
self
,
event
):
def
mouseMove
(
self
,
event
):
self
.
draw
.
move
(
"current"
,
event
.
x
-
self
.
lastx
,
event
.
y
-
self
.
lasty
)
self
.
draw
.
move
(
CURRENT
,
event
.
x
-
self
.
lastx
,
event
.
y
-
self
.
lasty
)
self
.
lastx
=
event
.
x
self
.
lastx
=
event
.
x
self
.
lasty
=
event
.
y
self
.
lasty
=
event
.
y
...
@@ -36,25 +34,22 @@ class Test(Frame):
...
@@ -36,25 +34,22 @@ class Test(Frame):
###### Event callbacks for canvas ITEMS (stuff drawn on the canvas)
###### Event callbacks for canvas ITEMS (stuff drawn on the canvas)
###################################################################
###################################################################
def
mouseEnter
(
self
,
event
):
def
mouseEnter
(
self
,
event
):
# the
"current"
tag is applied to the object the cursor is over.
# the
CURRENT
tag is applied to the object the cursor is over.
# this happens automatically.
# this happens automatically.
self
.
draw
.
itemconfig
(
"current"
,
{
"fill"
:
"red"
}
)
self
.
draw
.
itemconfig
(
CURRENT
,
fill
=
"red"
)
def
mouseLeave
(
self
,
event
):
def
mouseLeave
(
self
,
event
):
# the
"current"
tag is applied to the object the cursor is over.
# the
CURRENT
tag is applied to the object the cursor is over.
# this happens automatically.
# this happens automatically.
self
.
draw
.
itemconfig
(
"current"
,
{
"fill"
:
"blue"
})
self
.
draw
.
itemconfig
(
CURRENT
,
fill
=
"blue"
)
def
createWidgets
(
self
):
def
createWidgets
(
self
):
self
.
QUIT
=
Button
(
self
,
{
'text'
:
'QUIT'
,
self
.
QUIT
=
Button
(
self
,
text
=
'QUIT'
,
foreground
=
'red'
,
'fg'
:
'red'
,
command
=
self
.
quit
)
'command'
:
self
.
quit
})
self
.
QUIT
.
pack
(
side
=
LEFT
,
fill
=
BOTH
)
self
.
QUIT
.
pack
({
'side'
:
'left'
,
'fill'
:
'both'
})
self
.
draw
=
Canvas
(
self
,
width
=
"5i"
,
height
=
"5i"
)
self
.
draw
=
Canvas
(
self
,
{
"width"
:
"5i"
,
"height"
:
"5i"
})
self
.
draw
.
pack
(
side
=
LEFT
)
self
.
draw
.
pack
({
'side'
:
'left'
})
Widget
.
bind
(
self
.
draw
,
"<1>"
,
self
.
mouseDown
)
Widget
.
bind
(
self
.
draw
,
"<1>"
,
self
.
mouseDown
)
Widget
.
bind
(
self
.
draw
,
"<B1-Motion>"
,
self
.
mouseMove
)
Widget
.
bind
(
self
.
draw
,
"<B1-Motion>"
,
self
.
mouseMove
)
...
...
Demo/tkinter/matt/canvas-moving-w-mouse.py
View file @
21891d60
...
@@ -10,11 +10,10 @@ class Test(Frame):
...
@@ -10,11 +10,10 @@ class Test(Frame):
# remember where the mouse went down
# remember where the mouse went down
self
.
lastx
=
event
.
x
self
.
lastx
=
event
.
x
self
.
lasty
=
event
.
y
self
.
lasty
=
event
.
y
def
mouseMove
(
self
,
event
):
def
mouseMove
(
self
,
event
):
# whatever the mouse is over gets tagged as
"current"
for free by tk.
# whatever the mouse is over gets tagged as
CURRENT
for free by tk.
self
.
draw
.
move
(
"current"
,
event
.
x
-
self
.
lastx
,
event
.
y
-
self
.
lasty
)
self
.
draw
.
move
(
CURRENT
,
event
.
x
-
self
.
lastx
,
event
.
y
-
self
.
lasty
)
self
.
lastx
=
event
.
x
self
.
lastx
=
event
.
x
self
.
lasty
=
event
.
y
self
.
lasty
=
event
.
y
...
@@ -22,27 +21,24 @@ class Test(Frame):
...
@@ -22,27 +21,24 @@ class Test(Frame):
###### Event callbacks for canvas ITEMS (stuff drawn on the canvas)
###### Event callbacks for canvas ITEMS (stuff drawn on the canvas)
###################################################################
###################################################################
def
mouseEnter
(
self
,
event
):
def
mouseEnter
(
self
,
event
):
# the
"current"
tag is applied to the object the cursor is over.
# the
CURRENT
tag is applied to the object the cursor is over.
# this happens automatically.
# this happens automatically.
self
.
draw
.
itemconfig
(
"current"
,
{
"fill"
:
"red"
}
)
self
.
draw
.
itemconfig
(
CURRENT
,
fill
=
"red"
)
def
mouseLeave
(
self
,
event
):
def
mouseLeave
(
self
,
event
):
# the
"current"
tag is applied to the object the cursor is over.
# the
CURRENT
tag is applied to the object the cursor is over.
# this happens automatically.
# this happens automatically.
self
.
draw
.
itemconfig
(
"current"
,
{
"fill"
:
"blue"
})
self
.
draw
.
itemconfig
(
CURRENT
,
fill
=
"blue"
)
def
createWidgets
(
self
):
def
createWidgets
(
self
):
self
.
QUIT
=
Button
(
self
,
{
'text'
:
'QUIT'
,
self
.
QUIT
=
Button
(
self
,
text
=
'QUIT'
,
foreground
=
'red'
,
'fg'
:
'red'
,
command
=
self
.
quit
)
'command'
:
self
.
quit
})
self
.
QUIT
.
pack
(
side
=
LEFT
,
fill
=
BOTH
)
self
.
QUIT
.
pack
({
'side'
:
'left'
,
'fill'
:
'both'
})
self
.
draw
=
Canvas
(
self
,
width
=
"5i"
,
height
=
"5i"
)
self
.
draw
=
Canvas
(
self
,
{
"width"
:
"5i"
,
"height"
:
"5i"
})
self
.
draw
.
pack
(
side
=
LEFT
)
self
.
draw
.
pack
({
'side'
:
'left'
})
fred
=
self
.
draw
.
create_oval
(
0
,
0
,
20
,
20
,
fred
=
self
.
draw
.
create_oval
(
0
,
0
,
20
,
20
,
{
"fill"
:
"green"
,
"tag"
:
"selected"
}
)
fill
=
"green"
,
tags
=
"selected"
)
self
.
draw
.
tag_bind
(
fred
,
"<Any-Enter>"
,
self
.
mouseEnter
)
self
.
draw
.
tag_bind
(
fred
,
"<Any-Enter>"
,
self
.
mouseEnter
)
self
.
draw
.
tag_bind
(
fred
,
"<Any-Leave>"
,
self
.
mouseLeave
)
self
.
draw
.
tag_bind
(
fred
,
"<Any-Leave>"
,
self
.
mouseLeave
)
...
...
Demo/tkinter/matt/canvas-mult-item-sel.py
View file @
21891d60
...
@@ -11,20 +11,20 @@ class Test(Frame):
...
@@ -11,20 +11,20 @@ class Test(Frame):
###################################################################
###################################################################
def
mouseDown
(
self
,
event
):
def
mouseDown
(
self
,
event
):
# see if we're inside a dot. If we are, it
# see if we're inside a dot. If we are, it
# gets tagged as
"current"
for free by tk.
# gets tagged as
CURRENT
for free by tk.
if
not
event
.
widget
.
find_withtag
(
"current"
):
if
not
event
.
widget
.
find_withtag
(
CURRENT
):
# we clicked outside of all dots on the canvas. unselect all.
# we clicked outside of all dots on the canvas. unselect all.
# re-color everything back to an unselected color
# re-color everything back to an unselected color
self
.
draw
.
itemconfig
(
"selected"
,
{
"fill"
:
UNSELECTED_COLOR
}
)
self
.
draw
.
itemconfig
(
"selected"
,
fill
=
UNSELECTED_COLOR
)
# unselect everything
# unselect everything
self
.
draw
.
dtag
(
"selected"
)
self
.
draw
.
dtag
(
"selected"
)
else
:
else
:
# mark as "selected" the thing the cursor is under
# mark as "selected" the thing the cursor is under
self
.
draw
.
addtag
(
"selected"
,
"withtag"
,
"current"
)
self
.
draw
.
addtag
(
"selected"
,
"withtag"
,
CURRENT
)
# color it as selected
# color it as selected
self
.
draw
.
itemconfig
(
"selected"
,
{
"fill"
:
SELECTED_COLOR
}
)
self
.
draw
.
itemconfig
(
"selected"
,
fill
=
SELECTED_COLOR
)
self
.
lastx
=
event
.
x
self
.
lastx
=
event
.
x
self
.
lasty
=
event
.
y
self
.
lasty
=
event
.
y
...
@@ -38,40 +38,36 @@ class Test(Frame):
...
@@ -38,40 +38,36 @@ class Test(Frame):
def
makeNewDot
(
self
):
def
makeNewDot
(
self
):
# create a dot, and mark it as current
# create a dot, and mark it as current
fred
=
self
.
draw
.
create_oval
(
0
,
0
,
20
,
20
,
fred
=
self
.
draw
.
create_oval
(
0
,
0
,
20
,
20
,
{
"fill"
:
SELECTED_COLOR
,
"tag"
:
"current"
}
)
fill
=
SELECTED_COLOR
,
tags
=
CURRENT
)
# and make it selected
# and make it selected
self
.
draw
.
addtag
(
"selected"
,
"withtag"
,
"current"
)
self
.
draw
.
addtag
(
"selected"
,
"withtag"
,
CURRENT
)
def
createWidgets
(
self
):
def
createWidgets
(
self
):
self
.
QUIT
=
Button
(
self
,
{
'text'
:
'QUIT'
,
self
.
QUIT
=
Button
(
self
,
text
=
'QUIT'
,
foreground
=
'red'
,
'fg'
:
'red'
,
command
=
self
.
quit
)
'command'
:
self
.
quit
})
################
################
# make the canvas and bind some behavior to it
# make the canvas and bind some behavior to it
################
################
self
.
draw
=
Canvas
(
self
,
{
"width"
:
"5i"
,
"height"
:
"5i"
}
)
self
.
draw
=
Canvas
(
self
,
width
=
"5i"
,
height
=
"5i"
)
Widget
.
bind
(
self
.
draw
,
"<1>"
,
self
.
mouseDown
)
Widget
.
bind
(
self
.
draw
,
"<1>"
,
self
.
mouseDown
)
Widget
.
bind
(
self
.
draw
,
"<B1-Motion>"
,
self
.
mouseMove
)
Widget
.
bind
(
self
.
draw
,
"<B1-Motion>"
,
self
.
mouseMove
)
# and other things.....
# and other things.....
self
.
button
=
Button
(
self
,
{
"text"
:
"make a new dot"
,
self
.
button
=
Button
(
self
,
text
=
"make a new dot"
,
foreground
=
"blue"
,
"command"
:
self
.
makeNewDot
,
command
=
self
.
makeNewDot
)
"fg"
:
"blue"
})
message
=
(
"%s dots are selected and can be dragged.
\
n
"
self
.
label
=
Message
(
self
,
"%s are not selected.
\
n
"
{
"width"
:
"5i"
,
"Click in a dot to select it.
\
n
"
"text"
:
SELECTED_COLOR
+
" dots are selected and can be dragged.
\
n
"
+
"Click on empty space to deselect all dots."
UNSELECTED_COLOR
+
" are not selected.
\
n
"
+
)
%
(
SELECTED_COLOR
,
UNSELECTED_COLOR
)
"Click in a dot to select it.
\
n
"
+
self
.
label
=
Message
(
self
,
width
=
"5i"
,
text
=
message
)
"Click on empty space to deselect all dots."
})
self
.
QUIT
.
pack
(
side
=
BOTTOM
,
fill
=
BOTH
)
self
.
QUIT
.
pack
({
'side'
:
'bottom'
,
'fill'
:
'both'
})
self
.
label
.
pack
(
side
=
BOTTOM
,
fill
=
X
,
expand
=
1
)
self
.
label
.
pack
({
"side"
:
"bottom"
,
"fill"
:
"x"
,
"expand"
:
1
})
self
.
button
.
pack
(
side
=
BOTTOM
,
fill
=
X
)
self
.
button
.
pack
({
"side"
:
"bottom"
,
"fill"
:
"x"
})
self
.
draw
.
pack
(
side
=
LEFT
)
self
.
draw
.
pack
({
'side'
:
'left'
})
def
__init__
(
self
,
master
=
None
):
def
__init__
(
self
,
master
=
None
):
Frame
.
__init__
(
self
,
master
)
Frame
.
__init__
(
self
,
master
)
...
...
Demo/tkinter/matt/canvas-reading-tag-info.py
View file @
21891d60
...
@@ -6,17 +6,16 @@ class Test(Frame):
...
@@ -6,17 +6,16 @@ class Test(Frame):
print
"hi"
print
"hi"
def
createWidgets
(
self
):
def
createWidgets
(
self
):
self
.
QUIT
=
Button
(
self
,
{
'text'
:
'QUIT'
,
self
.
QUIT
=
Button
(
self
,
text
=
'QUIT'
,
foreground
=
'red'
,
'fg'
:
'red'
,
command
=
self
.
quit
)
'command'
:
self
.
quit
})
self
.
QUIT
.
pack
(
side
=
BOTTOM
,
fill
=
BOTH
)
self
.
QUIT
.
pack
({
'side'
:
'bottom'
,
'fill'
:
'both'
})
self
.
drawing
=
Canvas
(
self
,
{
"width"
:
"5i"
,
"height"
:
"5i"
}
)
self
.
drawing
=
Canvas
(
self
,
width
=
"5i"
,
height
=
"5i"
)
# make a shape
# make a shape
pgon
=
self
.
drawing
.
create_polygon
(
"10"
,
"10"
,
"110"
,
"10"
,
"110"
,
"110"
,
"10"
,
"110"
,
pgon
=
self
.
drawing
.
create_polygon
(
{
"fill"
:
"red"
,
10
,
10
,
110
,
10
,
110
,
110
,
10
,
110
,
"tags"
:
"weee foo groo"
}
)
fill
=
"red"
,
tags
=
(
"weee"
,
"foo"
,
"groo"
)
)
# this is how you query an object for its attributes
# this is how you query an object for its attributes
# config options FOR CANVAS ITEMS always come back in tuples of length 5.
# config options FOR CANVAS ITEMS always come back in tuples of length 5.
...
@@ -31,15 +30,14 @@ class Test(Frame):
...
@@ -31,15 +30,14 @@ class Test(Frame):
option_value
=
self
.
drawing
.
itemconfig
(
pgon
,
"stipple"
)
option_value
=
self
.
drawing
.
itemconfig
(
pgon
,
"stipple"
)
print
"pgon's current stipple value is -->"
,
option_value
[
4
],
"<--"
print
"pgon's current stipple value is -->"
,
option_value
[
4
],
"<--"
option_value
=
self
.
drawing
.
itemconfig
(
pgon
,
"fill"
)
option_value
=
self
.
drawing
.
itemconfig
(
pgon
,
"fill"
)
print
"pgon's current fill value is -->"
,
option_value
[
4
],
"<-- when he is usually colored -->"
,
option_value
[
3
],
"<--"
print
"pgon's current fill value is -->"
,
option_value
[
4
],
"<--"
print
" when he is usually colored -->"
,
option_value
[
3
],
"<--"
## here we print out all the tags associated with this object
## here we print out all the tags associated with this object
option_value
=
self
.
drawing
.
itemconfig
(
pgon
,
"tags"
)
option_value
=
self
.
drawing
.
itemconfig
(
pgon
,
"tags"
)
print
"pgon's tags are"
,
option_value
[
4
]
print
"pgon's tags are"
,
option_value
[
4
]
self
.
drawing
.
pack
({
'side'
:
'left'
})
self
.
drawing
.
pack
(
side
=
LEFT
)
def
__init__
(
self
,
master
=
None
):
def
__init__
(
self
,
master
=
None
):
Frame
.
__init__
(
self
,
master
)
Frame
.
__init__
(
self
,
master
)
...
...
Demo/tkinter/matt/canvas-w-widget-draw-el.py
View file @
21891d60
...
@@ -7,15 +7,14 @@ class Test(Frame):
...
@@ -7,15 +7,14 @@ class Test(Frame):
print
"hi"
print
"hi"
def
createWidgets
(
self
):
def
createWidgets
(
self
):
self
.
QUIT
=
Button
(
self
,
{
'text'
:
'QUIT'
,
self
.
QUIT
=
Button
(
self
,
text
=
'QUIT'
,
foreground
=
'red'
,
'fg'
:
'red'
,
command
=
self
.
quit
)
'command'
:
self
.
quit
})
self
.
QUIT
.
pack
(
side
=
BOTTOM
,
fill
=
BOTH
)
self
.
QUIT
.
pack
({
'side'
:
'bottom'
,
'fill'
:
'both'
})
self
.
draw
=
Canvas
(
self
,
{
"width"
:
"5i"
,
"height"
:
"5i"
}
)
self
.
draw
=
Canvas
(
self
,
width
=
"5i"
,
height
=
"5i"
)
self
.
button
=
Button
(
self
,
{
"text"
:
"this is a button"
,
self
.
button
=
Button
(
self
,
text
=
"this is a button"
,
"command"
:
self
.
printhi
}
)
command
=
self
.
printhi
)
# note here the coords are given in pixels (form the
# note here the coords are given in pixels (form the
# upper right and corner of the window, as usual for X)
# upper right and corner of the window, as usual for X)
...
@@ -23,11 +22,9 @@ class Test(Frame):
...
@@ -23,11 +22,9 @@ class Test(Frame):
# whatever...use the "anchor" option to control what point of the
# whatever...use the "anchor" option to control what point of the
# widget (in this case the button) gets mapped to the given x, y.
# widget (in this case the button) gets mapped to the given x, y.
# you can specify corners, edges, center, etc...
# you can specify corners, edges, center, etc...
self
.
draw
.
create_window
(
300
,
300
,
{
"window"
:
self
.
button
})
self
.
draw
.
create_window
(
300
,
300
,
window
=
self
.
button
)
self
.
draw
.
pack
({
'side'
:
'left'
})
self
.
draw
.
pack
(
side
=
LEFT
)
def
__init__
(
self
,
master
=
None
):
def
__init__
(
self
,
master
=
None
):
Frame
.
__init__
(
self
,
master
)
Frame
.
__init__
(
self
,
master
)
...
...
Demo/tkinter/matt/canvas-with-scrollbars.py
View file @
21891d60
...
@@ -10,27 +10,23 @@ class Test(Frame):
...
@@ -10,27 +10,23 @@ class Test(Frame):
print
"hi"
print
"hi"
def
createWidgets
(
self
):
def
createWidgets
(
self
):
self
.
question
=
Label
(
self
,
{
"text"
:
"Can Find The BLUE Square??????"
,
self
.
question
=
Label
(
self
,
text
=
"Can Find The BLUE Square??????"
)
Pack
:
{
"side"
:
"top"
}})
self
.
question
.
pack
()
self
.
QUIT
=
Button
(
self
,
{
'text'
:
'QUIT'
,
self
.
QUIT
=
Button
(
self
,
text
=
'QUIT'
,
background
=
'red'
,
'bg'
:
'red'
,
height
=
3
,
command
=
self
.
quit
)
"height"
:
"3"
,
self
.
QUIT
.
pack
(
side
=
BOTTOM
,
fill
=
BOTH
)
'command'
:
self
.
quit
})
spacer
=
Frame
(
self
,
height
=
"0.25i"
)
self
.
QUIT
.
pack
({
'side'
:
'bottom'
,
'fill'
:
'both'
})
spacer
.
pack
(
side
=
BOTTOM
)
spacer
=
Frame
(
self
,
{
"height"
:
"0.25i"
,
Pack
:
{
"side"
:
"bottom"
}})
# notice that the scroll region (20" x 20") is larger than
# notice that the scroll region (20" x 20") is larger than
# displayed size of the widget (5" x 5")
# displayed size of the widget (5" x 5")
self
.
draw
=
Canvas
(
self
,
{
"width"
:
"5i"
,
self
.
draw
=
Canvas
(
self
,
width
=
"5i"
,
height
=
"5i"
,
"height"
:
"5i"
,
background
=
"white"
,
"bg"
:
"white"
,
scrollregion
=
(
0
,
0
,
"20i"
,
"20i"
))
"scrollregion"
:
"0i 0i 20i 20i"
})
self
.
draw
.
scrollX
=
Scrollbar
(
self
,
orient
=
HORIZONTAL
)
self
.
draw
.
scrollX
=
Scrollbar
(
self
,
{
"orient"
:
"horizontal"
})
self
.
draw
.
scrollY
=
Scrollbar
(
self
,
orient
=
VERTICAL
)
self
.
draw
.
scrollY
=
Scrollbar
(
self
,
{
"orient"
:
"vertical"
})
# now tie the three together. This is standard boilerplate text
# now tie the three together. This is standard boilerplate text
self
.
draw
[
'xscrollcommand'
]
=
self
.
draw
.
scrollX
.
set
self
.
draw
[
'xscrollcommand'
]
=
self
.
draw
.
scrollX
.
set
...
@@ -40,16 +36,13 @@ class Test(Frame):
...
@@ -40,16 +36,13 @@ class Test(Frame):
# draw something. Note that the first square
# draw something. Note that the first square
# is visible, but you need to scroll to see the second one.
# is visible, but you need to scroll to see the second one.
self
.
draw
.
create_
polygon
(
"0i"
,
"0i"
,
"3.5i"
,
"0i"
,
"3.5i"
,
"3.5i"
,
"0i"
,
"3.5i
"
)
self
.
draw
.
create_
rectangle
(
0
,
0
,
"3.5i"
,
"3.5i"
,
fill
=
"black
"
)
self
.
draw
.
create_
polygon
(
"10i"
,
"10i"
,
"13.5i"
,
"10i"
,
"13.5i"
,
"13.5i"
,
"10i"
,
"13.5i"
,
"-fill"
,
"blue"
)
self
.
draw
.
create_
rectangle
(
"10i"
,
"10i"
,
"13.5i"
,
"13.5i"
,
fill
=
"blue"
)
# pack 'em up
# pack 'em up
self
.
draw
.
scrollX
.
pack
({
'side'
:
'bottom'
,
self
.
draw
.
scrollX
.
pack
(
side
=
BOTTOM
,
fill
=
X
)
"fill"
:
"x"
})
self
.
draw
.
scrollY
.
pack
(
side
=
RIGHT
,
fill
=
Y
)
self
.
draw
.
scrollY
.
pack
({
'side'
:
'right'
,
self
.
draw
.
pack
(
side
=
LEFT
)
"fill"
:
"y"
})
self
.
draw
.
pack
({
'side'
:
'left'
})
def
scrollCanvasX
(
self
,
*
args
):
def
scrollCanvasX
(
self
,
*
args
):
...
...
Demo/tkinter/matt/dialog-box.py
View file @
21891d60
from
Tkinter
import
*
from
Tkinter
import
*
from
Dialog
import
Dialog
# this shows how to create a new window with a button in it that can create new windows
# this shows how to create a new window with a button in it
# that can create new windows
class
Test
(
Frame
):
class
Test
(
Frame
):
def
printit
(
self
):
def
printit
(
self
):
print
"hi"
print
"hi"
def
makeWindow
(
self
):
def
makeWindow
(
self
):
# there is no Tkinter interface to the dialog box. Making one would mean putting
"""Create a top-level dialog with some buttons.
# a few wrapper functions in the Tkinter.py file.
# even better is to put in a SUIT-like selection of commonly-used dialogs.
# the parameters to this call are as follows:
fred
=
Toplevel
()
# a toplevel window that the dialog goes into
# this function returns the index of teh button chosen. In this case, 0 for "yes" and 1 for "no"
This uses the Dialog class, which is a wrapper around the Tcl/Tk
tk_dialog script. The function returns 0 if the user clicks 'yes'
print
self
.
tk
.
call
(
"tk_dialog"
,
# the command name
or 1 if the user clicks 'no'.
fred
,
# the name of a toplevel window
"""
"fred the dialog box"
,
# the title on the window
# the parameters to this call are as follows:
"click on a choice"
,
# the message to appear in the window
d
=
Dialog
(
"info"
,
# the bitmap (if any) to appear. If no bitmap is desired, pass ""
self
,
## name of a toplevel window
# legal values here are:
title
=
"fred the dialog box"
,
## title on the window
# string what it looks like
text
=
"click on a choice"
,
## message to appear in window
# ----------------------------------------------
bitmap
=
"info"
,
## bitmap (if any) to appear;
# error a circle with a slash through it
## if none, use ""
# grey25 grey square
# legal values here are:
# grey50 darker grey square
# string what it looks like
# hourglass use for "wait.."
# ----------------------------------------------
# info a large, lower case "i"
# error a circle with a slash through it
# questhead a human head with a "?" in it
# grey25 grey square
# question a large "?"
# grey50 darker grey square
# warning a large "!"
# hourglass use for "wait.."
# @fname any X bitmap where fname is the path to the file
# info a large, lower case "i"
#
# questhead a human head with a "?" in it
"0"
,
# the index of the default button choice. hitting return selects this
# question a large "?"
"yes"
,
"no"
)
# all remaining parameters are the labels for the
# warning a large "!"
# buttons that appear left to right in the dialog box
# @fname X bitmap where fname is the path to the file
#
default
=
0
,
# the index of the default button choice.
# hitting return selects this
strings
=
(
"yes"
,
"no"
))
# values of the 'strings' key are the labels for the
# buttons that appear left to right in the dialog box
return
d
.
num
def
createWidgets
(
self
):
def
createWidgets
(
self
):
self
.
QUIT
=
Button
(
self
,
{
'text'
:
'QUIT'
,
self
.
QUIT
=
Button
(
self
,
text
=
'QUIT'
,
foreground
=
'red'
,
'fg'
:
'red'
,
command
=
self
.
quit
)
'command'
:
self
.
quit
})
self
.
QUIT
.
pack
(
side
=
LEFT
,
fill
=
BOTH
)
self
.
QUIT
.
pack
({
'side'
:
'left'
,
'fill'
:
'both'
})
# a hello button
# a hello button
self
.
hi_there
=
Button
(
self
,
{
'text'
:
'Make a New Window'
,
self
.
hi_there
=
Button
(
self
,
text
=
'Make a New Window'
,
'command'
:
self
.
makeWindow
}
)
command
=
self
.
makeWindow
)
self
.
hi_there
.
pack
(
{
'side'
:
'left'
}
)
self
.
hi_there
.
pack
(
side
=
LEFT
)
def
__init__
(
self
,
master
=
None
):
def
__init__
(
self
,
master
=
None
):
...
...
Demo/tkinter/matt/entry-with-shared-variable.py
View file @
21891d60
...
@@ -11,10 +11,10 @@ class App(Frame):
...
@@ -11,10 +11,10 @@ class App(Frame):
self
.
entrythingy
=
Entry
()
self
.
entrythingy
=
Entry
()
self
.
entrythingy
.
pack
()
self
.
entrythingy
.
pack
()
self
.
button
=
Button
(
self
,
{
"text"
:
"Uppercase The Entry"
,
"command"
:
self
.
upper
})
self
.
button
=
Button
(
self
,
text
=
"Uppercase The Entry"
,
command
=
self
.
upper
)
self
.
button
.
pack
()
self
.
button
.
pack
()
# here we have the text in the entry widget tied to a variable.
# here we have the text in the entry widget tied to a variable.
# changes in the variable are echoed in the widget and vice versa.
# changes in the variable are echoed in the widget and vice versa.
# Very handy.
# Very handy.
...
@@ -22,7 +22,7 @@ class App(Frame):
...
@@ -22,7 +22,7 @@ class App(Frame):
# the other variable types that can be shadowed
# the other variable types that can be shadowed
self
.
contents
=
StringVar
()
self
.
contents
=
StringVar
()
self
.
contents
.
set
(
"this is a variable"
)
self
.
contents
.
set
(
"this is a variable"
)
self
.
entrythingy
.
config
(
{
"textvariable"
:
self
.
contents
}
)
self
.
entrythingy
.
config
(
textvariable
=
self
.
contents
)
# and here we get a callback when the user hits return. we could
# and here we get a callback when the user hits return. we could
# make the key that triggers the callback anything we wanted to.
# make the key that triggers the callback anything we wanted to.
...
...
Demo/tkinter/matt/killing-window-w-wm.py
View file @
21891d60
...
@@ -15,9 +15,8 @@ class Test(Frame):
...
@@ -15,9 +15,8 @@ class Test(Frame):
def
createWidgets
(
self
):
def
createWidgets
(
self
):
# a hello button
# a hello button
self
.
hi_there
=
Button
(
self
,
{
'text'
:
'Hello'
})
self
.
hi_there
=
Button
(
self
,
text
=
'Hello'
)
self
.
hi_there
.
pack
({
'side'
:
'left'
})
self
.
hi_there
.
pack
(
side
=
LEFT
)
def
__init__
(
self
,
master
=
None
):
def
__init__
(
self
,
master
=
None
):
Frame
.
__init__
(
self
,
master
)
Frame
.
__init__
(
self
,
master
)
...
...
Demo/tkinter/matt/menu-all-types-of-entries.py
View file @
21891d60
This diff is collapsed.
Click to expand it.
Demo/tkinter/matt/menu-simple.py
View file @
21891d60
...
@@ -43,33 +43,23 @@ def open_file():
...
@@ -43,33 +43,23 @@ def open_file():
def
makeFileMenu
():
def
makeFileMenu
():
# make menu button : "File"
# make menu button : "File"
File_button
=
Menubutton
(
mBar
,
{
'text'
:
'File'
,
File_button
=
Menubutton
(
mBar
,
text
=
'File'
,
underline
=
0
)
'underline'
:
0
,
File_button
.
pack
(
side
=
LEFT
,
padx
=
"1m"
)
Pack
:
{
'side'
:
'left'
,
'padx'
:
'1m'
}})
# make the pulldown part of the File menu. The parameter passed is the master.
# we attach it to the File button as a python attribute called "menu" by convention.
# hopefully this isn't too confusing...
File_button
.
menu
=
Menu
(
File_button
)
File_button
.
menu
=
Menu
(
File_button
)
# add an item. The first param is a menu entry type,
# add an item. The first param is a menu entry type,
# must be one of: "cascade", "checkbutton", "command", "radiobutton", "seperator"
# must be one of: "cascade", "checkbutton", "command", "radiobutton", "seperator"
# see menu-demo-2.py for examples of use
# see menu-demo-2.py for examples of use
File_button
.
menu
.
add
(
'command'
,
{
'label'
:
'New...'
,
File_button
.
menu
.
add_command
(
label
=
'New...'
,
underline
=
0
,
'underline'
:
0
,
command
=
new_file
)
'command'
:
new_file
})
File_button
.
menu
.
add
(
'command'
,
{
'label'
:
'Open...'
,
'underline'
:
0
,
'command'
:
open_file
})
File_button
.
menu
.
add
(
'command'
,
{
'label'
:
'Quit'
,
'underline'
:
0
,
'command'
:
'exit'
})
File_button
.
menu
.
add_command
(
label
=
'Open...'
,
underline
=
0
,
command
=
open_file
)
File_button
.
menu
.
add_command
(
label
=
'Quit'
,
underline
=
0
,
command
=
'exit'
)
# set up a pointer from the file menubutton back to the file menu
# set up a pointer from the file menubutton back to the file menu
File_button
[
'menu'
]
=
File_button
.
menu
File_button
[
'menu'
]
=
File_button
.
menu
...
@@ -78,22 +68,20 @@ def makeFileMenu():
...
@@ -78,22 +68,20 @@ def makeFileMenu():
def
makeEditMenu
():
def
makeEditMenu
():
Edit_button
=
Menubutton
(
mBar
,
{
'text'
:
'Edit'
,
Edit_button
=
Menubutton
(
mBar
,
text
=
'Edit'
,
underline
=
0
)
'underline'
:
0
,
Edit_button
.
pack
(
side
=
LEFT
,
padx
=
"1m"
)
Pack
:
{
'side'
:
'left'
,
'padx'
:
'1m'
}})
Edit_button
.
menu
=
Menu
(
Edit_button
)
Edit_button
.
menu
=
Menu
(
Edit_button
)
# just to be cute, let's disable the undo option:
# just to be cute, let's disable the undo option:
Edit_button
.
menu
.
add
(
'command'
,
{
"label"
:
"Undo"
}
)
Edit_button
.
menu
.
add
(
'command'
,
label
=
"Undo"
)
# undo is the 0th entry...
# undo is the 0th entry...
Edit_button
.
menu
.
entryconfig
(
0
,
{
"state"
:
"disabled"
}
)
Edit_button
.
menu
.
entryconfig
(
0
,
state
=
DISABLED
)
# and these are just for show. No "command" callbacks attached.
# and these are just for show. No "command" callbacks attached.
Edit_button
.
menu
.
add
(
'command'
,
{
"label"
:
"Cut"
}
)
Edit_button
.
menu
.
add
_command
(
label
=
"Cut"
)
Edit_button
.
menu
.
add
(
'command'
,
{
"label"
:
"Copy"
}
)
Edit_button
.
menu
.
add
_command
(
label
=
"Copy"
)
Edit_button
.
menu
.
add
(
'command'
,
{
"label"
:
"Paste"
}
)
Edit_button
.
menu
.
add
_command
(
label
=
"Paste"
)
# set up a pointer from the file menubutton back to the file menu
# set up a pointer from the file menubutton back to the file menu
Edit_button
[
'menu'
]
=
Edit_button
.
menu
Edit_button
[
'menu'
]
=
Edit_button
.
menu
...
@@ -107,10 +95,8 @@ root = Tk()
...
@@ -107,10 +95,8 @@ root = Tk()
# make a menu bar
# make a menu bar
mBar
=
Frame
(
root
,
{
'relief'
:
'raised'
,
mBar
=
Frame
(
root
,
relief
=
RAISED
,
borderwidth
=
2
)
'bd'
:
2
,
mBar
.
pack
(
fill
=
X
)
Pack
:
{
'side'
:
'top'
,
'fill'
:
'x'
}})
File_button
=
makeFileMenu
()
File_button
=
makeFileMenu
()
Edit_button
=
makeEditMenu
()
Edit_button
=
makeEditMenu
()
...
@@ -119,7 +105,6 @@ Edit_button = makeEditMenu()
...
@@ -119,7 +105,6 @@ Edit_button = makeEditMenu()
# This allows for scanning from one menubutton to the next.
# This allows for scanning from one menubutton to the next.
mBar
.
tk_menuBar
(
File_button
,
Edit_button
)
mBar
.
tk_menuBar
(
File_button
,
Edit_button
)
root
.
title
(
'menu demo'
)
root
.
title
(
'menu demo'
)
root
.
iconname
(
'packer'
)
root
.
iconname
(
'packer'
)
...
...
Demo/tkinter/matt/not-what-you-might-think-1.py
View file @
21891d60
...
@@ -4,19 +4,15 @@ from Tkinter import *
...
@@ -4,19 +4,15 @@ from Tkinter import *
class
Test
(
Frame
):
class
Test
(
Frame
):
def
createWidgets
(
self
):
def
createWidgets
(
self
):
self
.
Gpanel
=
Frame
(
self
,
{
'width'
:
'1i'
,
self
.
Gpanel
=
Frame
(
self
,
width
=
'1i'
,
height
=
'1i'
,
'height'
:
'1i'
,
background
=
'green'
)
'bg'
:
'green'
})
self
.
Gpanel
.
pack
(
side
=
LEFT
)
self
.
Gpanel
.
pack
({
'side'
:
'left'
})
# a QUIT button
# a QUIT button
self
.
Gpanel
.
QUIT
=
Button
(
self
.
Gpanel
,
{
'text'
:
'QUIT'
,
self
.
Gpanel
.
QUIT
=
Button
(
self
.
Gpanel
,
text
=
'QUIT'
,
'fg'
:
'red'
,
foreground
=
'red'
,
'command'
:
self
.
quit
})
command
=
self
.
quit
)
self
.
Gpanel
.
QUIT
.
pack
(
{
'side'
:
'left'
})
self
.
Gpanel
.
QUIT
.
pack
(
side
=
LEFT
)
def
__init__
(
self
,
master
=
None
):
def
__init__
(
self
,
master
=
None
):
...
...
Demo/tkinter/matt/not-what-you-might-think-2.py
View file @
21891d60
...
@@ -4,25 +4,18 @@ from Tkinter import *
...
@@ -4,25 +4,18 @@ from Tkinter import *
class
Test
(
Frame
):
class
Test
(
Frame
):
def
createWidgets
(
self
):
def
createWidgets
(
self
):
self
.
Gpanel
=
Frame
(
self
,
{
'width'
:
'1i'
,
self
.
Gpanel
=
Frame
(
self
,
width
=
'1i'
,
height
=
'1i'
,
'height'
:
'1i'
,
background
=
'green'
)
'bg'
:
'green'
})
# this line turns off the recalculation of geometry by masters.
# this line turns off the recalculation of geometry by masters.
self
.
Gpanel
.
tk
.
call
(
'pack'
,
'propagate'
,
str
(
self
.
Gpanel
),
"0"
)
self
.
Gpanel
.
propagate
(
0
)
self
.
Gpanel
.
pack
({
'side'
:
'left'
})
self
.
Gpanel
.
pack
(
side
=
LEFT
)
# a QUIT button
# a QUIT button
self
.
Gpanel
.
QUIT
=
Button
(
self
.
Gpanel
,
{
'text'
:
'QUIT'
,
self
.
Gpanel
.
QUIT
=
Button
(
self
.
Gpanel
,
text
=
'QUIT'
,
foreground
=
'red'
,
'fg'
:
'red'
,
command
=
self
.
quit
)
'command'
:
self
.
quit
})
self
.
Gpanel
.
QUIT
.
pack
(
side
=
LEFT
)
self
.
Gpanel
.
QUIT
.
pack
(
{
'side'
:
'left'
})
def
__init__
(
self
,
master
=
None
):
def
__init__
(
self
,
master
=
None
):
Frame
.
__init__
(
self
,
master
)
Frame
.
__init__
(
self
,
master
)
...
...
Demo/tkinter/matt/packer-and-placer-together.py
View file @
21891d60
...
@@ -5,8 +5,7 @@ from Tkinter import *
...
@@ -5,8 +5,7 @@ from Tkinter import *
def
do_motion
(
event
):
def
do_motion
(
event
):
app
.
button
.
place
({
'x'
:
event
.
x
,
app
.
button
.
place
(
x
=
event
.
x
,
y
=
event
.
y
)
'y'
:
event
.
y
})
def
dothis
():
def
dothis
():
print
'calling me!'
print
'calling me!'
...
@@ -16,27 +15,20 @@ def createWidgets(top):
...
@@ -16,27 +15,20 @@ def createWidgets(top):
# and the window containing is 400x400. We do this
# and the window containing is 400x400. We do this
# simply to show that this is possible. The rest of the
# simply to show that this is possible. The rest of the
# area is inaccesssible.
# area is inaccesssible.
f
=
Frame
(
top
,
{
'width'
:
'200'
,
f
=
Frame
(
top
,
width
=
200
,
height
=
200
,
background
=
'green'
)
'height'
:
'200'
,
'bg'
:
'green'
})
# note that we use a different manager here.
# note that we use a different manager here.
# This way, the top level frame widget resizes when the
# This way, the top level frame widget resizes when the
# application window does.
# application window does.
f
.
pack
({
'fill'
:
'both'
,
f
.
pack
(
fill
=
BOTH
,
expand
=
1
)
'expand'
:
1
})
# now make a button
# now make a button
f
.
button
=
Button
(
f
,
{
'fg'
:
'red'
,
f
.
button
=
Button
(
f
,
foreground
=
'red'
,
text
=
'amazing'
,
command
=
dothis
)
'text'
:
'amazing'
,
'command'
:
dothis
})
# and place it so that the nw corner is
# and place it so that the nw corner is
# 1/2 way along the top X edge of its' parent
# 1/2 way along the top X edge of its' parent
f
.
button
.
place
({
'relx'
:
'0.5'
,
f
.
button
.
place
(
relx
=
0.5
,
rely
=
0.0
,
anchor
=
NW
)
'rely'
:
'0.0'
,
'anchor'
:
'nw'
})
# allow the user to move the button SUIT-style.
# allow the user to move the button SUIT-style.
f
.
bind
(
'<Control-Shift-Motion>'
,
do_motion
)
f
.
bind
(
'<Control-Shift-Motion>'
,
do_motion
)
...
...
Demo/tkinter/matt/packer-simple.py
View file @
21891d60
...
@@ -7,23 +7,20 @@ class Test(Frame):
...
@@ -7,23 +7,20 @@ class Test(Frame):
def
createWidgets
(
self
):
def
createWidgets
(
self
):
# a hello button
# a hello button
self
.
QUIT
=
Button
(
self
,
{
'text'
:
'QUIT'
,
self
.
QUIT
=
Button
(
self
,
text
=
'QUIT'
,
foreground
=
'red'
,
'fg'
:
'red'
,
command
=
self
.
quit
)
'command'
:
self
.
quit
})
self
.
QUIT
.
pack
(
side
=
LEFT
,
fill
=
BOTH
)
self
.
QUIT
.
pack
({
'side'
:
'left'
,
'fill'
:
'both'
})
self
.
hi_there
=
Button
(
self
,
text
=
'Hello'
,
command
=
self
.
printit
)
self
.
hi_there
.
pack
(
side
=
LEFT
)
self
.
hi_there
=
Button
(
self
,
{
'text'
:
'Hello'
,
# note how Packer defaults to side=TOP
'command'
:
self
.
printit
})
self
.
hi_there
.
pack
({
'side'
:
'left'
})
# note how Packer defaults to {'side': 'top'}
self
.
guy2
=
Button
(
self
,
text
=
'button 2'
)
self
.
guy2
=
Button
(
self
,
{
'text'
:
'button 2'
})
self
.
guy2
.
pack
()
self
.
guy2
.
pack
()
self
.
guy3
=
Button
(
self
,
{
'text'
:
'button 3'
}
)
self
.
guy3
=
Button
(
self
,
text
=
'button 3'
)
self
.
guy3
.
pack
()
self
.
guy3
.
pack
()
def
__init__
(
self
,
master
=
None
):
def
__init__
(
self
,
master
=
None
):
...
...
Demo/tkinter/matt/placer-simple.py
View file @
21891d60
...
@@ -3,8 +3,7 @@ from Tkinter import *
...
@@ -3,8 +3,7 @@ from Tkinter import *
# This is a program that tests the placer geom manager
# This is a program that tests the placer geom manager
def
do_motion
(
event
):
def
do_motion
(
event
):
app
.
button
.
place
({
'x'
:
event
.
x
,
app
.
button
.
place
(
x
=
event
.
x
,
y
=
event
.
y
)
'y'
:
event
.
y
})
def
dothis
():
def
dothis
():
print
'calling me!'
print
'calling me!'
...
@@ -14,27 +13,20 @@ def createWidgets(top):
...
@@ -14,27 +13,20 @@ def createWidgets(top):
# and the window containing is 400x400. We do this
# and the window containing is 400x400. We do this
# simply to show that this is possible. The rest of the
# simply to show that this is possible. The rest of the
# area is inaccesssible.
# area is inaccesssible.
f
=
Frame
(
top
,
{
'width'
:
'200'
,
f
=
Frame
(
top
,
width
=
200
,
height
=
200
,
background
=
'green'
)
'height'
:
'200'
,
'bg'
:
'green'
})
# place it so the upper left hand corner of
# place it so the upper left hand corner of
# the frame is in the upper left corner of
# the frame is in the upper left corner of
# the parent
# the parent
f
.
place
({
'relx'
:
'0.0'
,
f
.
place
(
relx
=
0.0
,
rely
=
0.0
)
'rely'
:
'0.0'
})
# now make a button
# now make a button
f
.
button
=
Button
(
f
,
{
'fg'
:
'red'
,
f
.
button
=
Button
(
f
,
foreground
=
'red'
,
text
=
'amazing'
,
command
=
dothis
)
'text'
:
'amazing'
,
'command'
:
dothis
})
# and place it so that the nw corner is
# and place it so that the nw corner is
# 1/2 way along the top X edge of its' parent
# 1/2 way along the top X edge of its' parent
f
.
button
.
place
({
'relx'
:
'0.5'
,
f
.
button
.
place
(
relx
=
0.5
,
rely
=
0.0
,
anchor
=
NW
)
'rely'
:
'0.0'
,
'anchor'
:
'nw'
})
# allow the user to move the button SUIT-style.
# allow the user to move the button SUIT-style.
f
.
bind
(
'<Control-Shift-Motion>'
,
do_motion
)
f
.
bind
(
'<Control-Shift-Motion>'
,
do_motion
)
...
...
Demo/tkinter/matt/pong-demo-1.py
View file @
21891d60
...
@@ -5,31 +5,28 @@ import string
...
@@ -5,31 +5,28 @@ import string
class
Pong
(
Frame
):
class
Pong
(
Frame
):
def
createWidgets
(
self
):
def
createWidgets
(
self
):
self
.
QUIT
=
Button
(
self
,
{
'text'
:
'QUIT'
,
self
.
QUIT
=
Button
(
self
,
text
=
'QUIT'
,
foreground
=
'red'
,
'fg'
:
'red'
,
command
=
self
.
quit
)
'command'
:
self
.
quit
})
self
.
QUIT
.
pack
(
side
=
LEFT
,
fill
=
BOTH
)
self
.
QUIT
.
pack
({
'side'
:
'left'
,
'fill'
:
'both'
})
## The playing field
## The playing field
self
.
draw
=
Canvas
(
self
,
{
"width"
:
"5i"
,
"height"
:
"5i"
}
)
self
.
draw
=
Canvas
(
self
,
width
=
"5i"
,
height
=
"5i"
)
## The speed control for the ball
## The speed control for the ball
self
.
speed
=
Scale
(
self
,
{
"orient"
:
"horiz"
,
self
.
speed
=
Scale
(
self
,
orient
=
HORIZONTAL
,
label
=
"ball speed"
,
"label"
:
"ball speed"
,
from_
=-
100
,
to
=
100
)
"from"
:
-
100
,
"to"
:
100
})
self
.
speed
.
pack
(
{
'side'
:
'bottom'
,
"fill"
:
"x"
}
)
self
.
speed
.
pack
(
side
=
BOTTOM
,
fill
=
X
)
# The ball
# The ball
self
.
ball
=
self
.
draw
.
create_oval
(
"0i"
,
"0i"
,
"0.10i"
,
"0.10i"
,
{
"fill"
:
"red"
})
self
.
ball
=
self
.
draw
.
create_oval
(
"0i"
,
"0i"
,
"0.10i"
,
"0.10i"
,
fill
=
"red"
)
self
.
x
=
0.05
self
.
x
=
0.05
self
.
y
=
0.05
self
.
y
=
0.05
self
.
velocity_x
=
0.3
self
.
velocity_x
=
0.3
self
.
velocity_y
=
0.5
self
.
velocity_y
=
0.5
self
.
draw
.
pack
({
'side'
:
'left'
})
self
.
draw
.
pack
(
side
=
LEFT
)
def
moveBall
(
self
,
*
args
):
def
moveBall
(
self
,
*
args
):
if
(
self
.
x
>
5.0
)
or
(
self
.
x
<
0.0
):
if
(
self
.
x
>
5.0
)
or
(
self
.
x
<
0.0
):
...
@@ -44,8 +41,6 @@ class Pong(Frame):
...
@@ -44,8 +41,6 @@ class Pong(Frame):
self
.
draw
.
move
(
self
.
ball
,
`deltax`
+
"i"
,
`deltay`
+
"i"
)
self
.
draw
.
move
(
self
.
ball
,
`deltax`
+
"i"
,
`deltay`
+
"i"
)
self
.
after
(
10
,
self
.
moveBall
)
self
.
after
(
10
,
self
.
moveBall
)
def
__init__
(
self
,
master
=
None
):
def
__init__
(
self
,
master
=
None
):
Frame
.
__init__
(
self
,
master
)
Frame
.
__init__
(
self
,
master
)
...
...
Demo/tkinter/matt/printing-coords-of-items.py
View file @
21891d60
...
@@ -8,26 +8,23 @@ class Test(Frame):
...
@@ -8,26 +8,23 @@ class Test(Frame):
###################################################################
###################################################################
def
mouseDown
(
self
,
event
):
def
mouseDown
(
self
,
event
):
# see if we're inside a dot. If we are, it
# see if we're inside a dot. If we are, it
# gets tagged as
"current"
for free by tk.
# gets tagged as
CURRENT
for free by tk.
if
not
event
.
widget
.
find_withtag
(
"current"
):
if
not
event
.
widget
.
find_withtag
(
CURRENT
):
# there is no dot here, so we can make one,
# there is no dot here, so we can make one,
# and bind some interesting behavior to it.
# and bind some interesting behavior to it.
# ------
# ------
# create a dot, and mark it as current
# create a dot, and mark it as current
fred
=
self
.
draw
.
create_oval
(
event
.
x
-
10
,
event
.
y
-
10
,
event
.
x
+
10
,
event
.
y
+
10
,
fred
=
self
.
draw
.
create_oval
(
{
"fill"
:
"green"
,
"tag"
:
"current"
})
event
.
x
-
10
,
event
.
y
-
10
,
event
.
x
+
10
,
event
.
y
+
10
,
fill
=
"green"
)
self
.
draw
.
bind
(
fred
,
"<Any-Enter>"
,
self
.
mouseEnter
)
self
.
draw
.
tag_bind
(
fred
,
"<Enter>"
,
self
.
mouseEnter
)
self
.
draw
.
bind
(
fred
,
"<Any-Leave>"
,
self
.
mouseLeave
)
self
.
draw
.
tag_bind
(
fred
,
"<Leave>"
,
self
.
mouseLeave
)
self
.
lastx
=
event
.
x
self
.
lastx
=
event
.
x
self
.
lasty
=
event
.
y
self
.
lasty
=
event
.
y
def
mouseMove
(
self
,
event
):
def
mouseMove
(
self
,
event
):
self
.
draw
.
move
(
"current"
,
event
.
x
-
self
.
lastx
,
event
.
y
-
self
.
lasty
)
self
.
draw
.
move
(
CURRENT
,
event
.
x
-
self
.
lastx
,
event
.
y
-
self
.
lasty
)
self
.
lastx
=
event
.
x
self
.
lastx
=
event
.
x
self
.
lasty
=
event
.
y
self
.
lasty
=
event
.
y
...
@@ -37,23 +34,21 @@ class Test(Frame):
...
@@ -37,23 +34,21 @@ class Test(Frame):
def
mouseEnter
(
self
,
event
):
def
mouseEnter
(
self
,
event
):
# the "current" tag is applied to the object the cursor is over.
# the "current" tag is applied to the object the cursor is over.
# this happens automatically.
# this happens automatically.
self
.
draw
.
itemconfig
(
"current"
,
{
"fill"
:
"red"
}
)
self
.
draw
.
itemconfig
(
CURRENT
,
fill
=
"red"
)
print
self
.
tk
.
splitlist
(
self
.
draw
.
coords
(
"current"
)
)
print
self
.
draw
.
coords
(
CURRENT
)
def
mouseLeave
(
self
,
event
):
def
mouseLeave
(
self
,
event
):
# the "current" tag is applied to the object the cursor is over.
# the "current" tag is applied to the object the cursor is over.
# this happens automatically.
# this happens automatically.
self
.
draw
.
itemconfig
(
"current"
,
{
"fill"
:
"blue"
}
)
self
.
draw
.
itemconfig
(
CURRENT
,
fill
=
"blue"
)
def
createWidgets
(
self
):
def
createWidgets
(
self
):
self
.
QUIT
=
Button
(
self
,
{
'text'
:
'QUIT'
,
self
.
QUIT
=
Button
(
self
,
text
=
'QUIT'
,
foreground
=
'red'
,
'fg'
:
'red'
,
command
=
self
.
quit
)
'command'
:
self
.
quit
})
self
.
QUIT
.
pack
(
side
=
LEFT
,
fill
=
BOTH
)
self
.
QUIT
.
pack
({
'side'
:
'left'
,
'fill'
:
'both'
})
self
.
draw
=
Canvas
(
self
,
width
=
"5i"
,
height
=
"5i"
)
self
.
draw
=
Canvas
(
self
,
{
"width"
:
"5i"
,
"height"
:
"5i"
})
self
.
draw
.
pack
(
side
=
LEFT
)
self
.
draw
.
pack
({
'side'
:
'left'
})
Widget
.
bind
(
self
.
draw
,
"<1>"
,
self
.
mouseDown
)
Widget
.
bind
(
self
.
draw
,
"<1>"
,
self
.
mouseDown
)
Widget
.
bind
(
self
.
draw
,
"<B1-Motion>"
,
self
.
mouseMove
)
Widget
.
bind
(
self
.
draw
,
"<B1-Motion>"
,
self
.
mouseMove
)
...
...
Demo/tkinter/matt/radiobutton-simple.py
View file @
21891d60
...
@@ -26,34 +26,30 @@ class Test(Frame):
...
@@ -26,34 +26,30 @@ class Test(Frame):
# 'variable' is the name of the variable that all these radio buttons share
# 'variable' is the name of the variable that all these radio buttons share
# 'value' is the value this variable takes on when the radio button is selected
# 'value' is the value this variable takes on when the radio button is selected
# 'anchor' makes the text appear left justified (default is centered. ick)
# 'anchor' makes the text appear left justified (default is centered. ick)
self
.
radioframe
.
choc
=
Radiobutton
(
self
.
radioframe
,
{
"text"
:
"Chocolate Flavor"
,
self
.
radioframe
.
choc
=
Radiobutton
(
"variable"
:
self
.
flavor
,
self
.
radioframe
,
text
=
"Chocolate Flavor"
,
"value"
:
"chocolate"
,
variable
=
self
.
flavor
,
value
=
"chocolate"
,
"anchor"
:
"w"
,
anchor
=
W
)
Pack
:
{
"side"
:
"top"
,
"fill"
:
"x"
}})
self
.
radioframe
.
choc
.
pack
(
fill
=
X
)
self
.
radioframe
.
straw
=
Radiobutton
(
self
.
radioframe
,
{
"text"
:
"Strawberry Flavor"
,
self
.
radioframe
.
straw
=
Radiobutton
(
"variable"
:
self
.
flavor
,
self
.
radioframe
,
text
=
"Strawberry Flavor"
,
"anchor"
:
"w"
,
variable
=
self
.
flavor
,
value
=
"strawberry"
,
"value"
:
"strawberry"
,
anchor
=
W
)
Pack
:
{
"side"
:
"top"
,
"fill"
:
"x"
}})
self
.
radioframe
.
straw
.
pack
(
fill
=
X
)
self
.
radioframe
.
lemon
=
Radiobutton
(
self
.
radioframe
,
{
"text"
:
"Lemon Flavor"
,
self
.
radioframe
.
lemon
=
Radiobutton
(
"anchor"
:
"w"
,
self
.
radioframe
,
text
=
"Lemon Flavor"
,
"variable"
:
self
.
flavor
,
variable
=
self
.
flavor
,
value
=
"lemon"
,
"value"
:
"lemon"
,
anchor
=
W
)
Pack
:
{
"side"
:
"top"
,
"fill"
:
"x"
}})
self
.
radioframe
.
lemon
.
pack
(
fill
=
X
)
# this is a text entry that lets you type in the name of a flavor too.
# this is a text entry that lets you type in the name of a flavor too.
self
.
entry
=
Entry
(
self
,
{
"textvariable"
:
self
.
flavor
,
self
.
entry
=
Entry
(
self
,
textvariable
=
self
.
flavor
)
Pack
:
{
"side"
:
"top"
,
"fill"
:
"x"
}})
self
.
entry
.
pack
(
fill
=
X
)
self
.
QUIT
=
Button
(
self
,
{
'text'
:
'QUIT'
,
self
.
QUIT
=
Button
(
self
,
text
=
'QUIT'
,
foreground
=
'red'
,
'fg'
:
'red'
,
command
=
self
.
quit
)
'command'
:
self
.
quit
})
self
.
QUIT
.
pack
(
side
=
BOTTOM
,
fill
=
BOTH
)
self
.
QUIT
.
pack
({
'side'
:
'bottom'
,
'fill'
:
'both'
})
def
__init__
(
self
,
master
=
None
):
def
__init__
(
self
,
master
=
None
):
...
...
Demo/tkinter/matt/rubber-band-box-demo-1.py
View file @
21891d60
...
@@ -5,15 +5,15 @@ class Test(Frame):
...
@@ -5,15 +5,15 @@ class Test(Frame):
print
"hi"
print
"hi"
def
createWidgets
(
self
):
def
createWidgets
(
self
):
self
.
QUIT
=
Button
(
self
,
{
'text'
:
'QUIT'
,
self
.
QUIT
=
Button
(
self
,
text
=
'QUIT'
,
'bg'
:
'red'
,
background
=
'red'
,
'fg'
:
'white'
,
foreground
=
'white'
,
'height'
:
3
,
height
=
3
,
'command'
:
self
.
quit
}
)
command
=
self
.
quit
)
self
.
QUIT
.
pack
(
{
'side'
:
'bottom'
,
'fill'
:
'both'
})
self
.
QUIT
.
pack
(
side
=
BOTTOM
,
fill
=
BOTH
)
self
.
canvasObject
=
Canvas
(
self
,
{
"width"
:
"5i"
,
"height"
:
"5i"
}
)
self
.
canvasObject
=
Canvas
(
self
,
width
=
"5i"
,
height
=
"5i"
)
self
.
canvasObject
.
pack
(
{
'side'
:
'left'
}
)
self
.
canvasObject
.
pack
(
side
=
LEFT
)
def
mouseDown
(
self
,
event
):
def
mouseDown
(
self
,
event
):
# canvas x and y take the screen coords from the event and translate
# canvas x and y take the screen coords from the event and translate
...
@@ -29,7 +29,8 @@ class Test(Frame):
...
@@ -29,7 +29,8 @@ class Test(Frame):
if
(
self
.
startx
!=
event
.
x
)
and
(
self
.
starty
!=
event
.
y
)
:
if
(
self
.
startx
!=
event
.
x
)
and
(
self
.
starty
!=
event
.
y
)
:
self
.
canvasObject
.
delete
(
self
.
rubberbandBox
)
self
.
canvasObject
.
delete
(
self
.
rubberbandBox
)
self
.
rubberbandBox
=
self
.
canvasObject
.
create_rectangle
(
self
.
startx
,
self
.
starty
,
x
,
y
)
self
.
rubberbandBox
=
self
.
canvasObject
.
create_rectangle
(
self
.
startx
,
self
.
starty
,
x
,
y
)
# this flushes the output, making sure that
# this flushes the output, making sure that
# the rectangle makes it to the screen
# the rectangle makes it to the screen
# before the next event is handled
# before the next event is handled
...
@@ -50,7 +51,7 @@ class Test(Frame):
...
@@ -50,7 +51,7 @@ class Test(Frame):
Widget
.
bind
(
self
.
canvasObject
,
"<Button-1>"
,
self
.
mouseDown
)
Widget
.
bind
(
self
.
canvasObject
,
"<Button-1>"
,
self
.
mouseDown
)
Widget
.
bind
(
self
.
canvasObject
,
"<Button1-Motion>"
,
self
.
mouseMotion
)
Widget
.
bind
(
self
.
canvasObject
,
"<Button1-Motion>"
,
self
.
mouseMotion
)
Widget
.
bind
(
self
.
canvasObject
,
"<Button1-ButtonRelease>"
,
self
.
mouseUp
)
Widget
.
bind
(
self
.
canvasObject
,
"<Button1-ButtonRelease>"
,
self
.
mouseUp
)
test
=
Test
()
test
=
Test
()
...
...
Demo/tkinter/matt/rubber-line-demo-1.py
View file @
21891d60
...
@@ -5,15 +5,15 @@ class Test(Frame):
...
@@ -5,15 +5,15 @@ class Test(Frame):
print
"hi"
print
"hi"
def
createWidgets
(
self
):
def
createWidgets
(
self
):
self
.
QUIT
=
Button
(
self
,
{
'text'
:
'QUIT'
,
self
.
QUIT
=
Button
(
self
,
text
=
'QUIT'
,
'bg'
:
'red'
,
background
=
'red'
,
'fg'
:
'white'
,
foreground
=
'white'
,
'height'
:
3
,
height
=
3
,
'command'
:
self
.
quit
}
)
command
=
self
.
quit
)
self
.
QUIT
.
pack
(
{
'side'
:
'bottom'
,
'fill'
:
'both'
})
self
.
QUIT
.
pack
(
side
=
BOTTOM
,
fill
=
BOTH
)
self
.
canvasObject
=
Canvas
(
self
,
{
"width"
:
"5i"
,
"height"
:
"5i"
}
)
self
.
canvasObject
=
Canvas
(
self
,
width
=
"5i"
,
height
=
"5i"
)
self
.
canvasObject
.
pack
(
{
'side'
:
'left'
}
)
self
.
canvasObject
.
pack
(
side
=
LEFT
)
def
mouseDown
(
self
,
event
):
def
mouseDown
(
self
,
event
):
# canvas x and y take the screen coords from the event and translate
# canvas x and y take the screen coords from the event and translate
...
@@ -29,7 +29,8 @@ class Test(Frame):
...
@@ -29,7 +29,8 @@ class Test(Frame):
if
(
self
.
startx
!=
event
.
x
)
and
(
self
.
starty
!=
event
.
y
)
:
if
(
self
.
startx
!=
event
.
x
)
and
(
self
.
starty
!=
event
.
y
)
:
self
.
canvasObject
.
delete
(
self
.
rubberbandLine
)
self
.
canvasObject
.
delete
(
self
.
rubberbandLine
)
self
.
rubberbandLine
=
self
.
canvasObject
.
create_line
(
self
.
startx
,
self
.
starty
,
x
,
y
)
self
.
rubberbandLine
=
self
.
canvasObject
.
create_line
(
self
.
startx
,
self
.
starty
,
x
,
y
)
# this flushes the output, making sure that
# this flushes the output, making sure that
# the rectangle makes it to the screen
# the rectangle makes it to the screen
# before the next event is handled
# before the next event is handled
...
...
Demo/tkinter/matt/slider-demo-1.py
View file @
21891d60
...
@@ -11,25 +11,21 @@ class Test(Frame):
...
@@ -11,25 +11,21 @@ class Test(Frame):
self
.
slider
.
set
(
0
)
self
.
slider
.
set
(
0
)
def
createWidgets
(
self
):
def
createWidgets
(
self
):
self
.
slider
=
Scale
(
self
,
{
"from"
:
0
,
self
.
slider
=
Scale
(
self
,
from_
=
0
,
to
=
100
,
'to'
:
100
,
orient
=
HORIZONTAL
,
"orient"
:
"horizontal"
,
length
=
"3i"
,
"length"
:
"3i"
,
label
=
"happy slider"
,
"label"
:
"happy slider"
,
command
=
self
.
print_value
)
'command'
:
self
.
print_value
})
self
.
reset
=
Button
(
self
,
text
=
'reset slider'
,
self
.
reset
=
Button
(
self
,
{
'text'
:
'reset slider'
,
command
=
self
.
reset
)
'command'
:
self
.
reset
})
self
.
QUIT
=
Button
(
self
,
text
=
'QUIT'
,
foreground
=
'red'
,
command
=
self
.
quit
)
self
.
QUIT
=
Button
(
self
,
{
'text'
:
'QUIT'
,
'fg'
:
'red'
,
self
.
slider
.
pack
(
side
=
LEFT
)
'command'
:
self
.
quit
})
self
.
reset
.
pack
(
side
=
LEFT
)
self
.
QUIT
.
pack
(
side
=
LEFT
,
fill
=
BOTH
)
self
.
slider
.
pack
({
'side'
:
'left'
})
self
.
reset
.
pack
({
'side'
:
'left'
})
self
.
QUIT
.
pack
({
'side'
:
'left'
,
'fill'
:
'both'
})
def
__init__
(
self
,
master
=
None
):
def
__init__
(
self
,
master
=
None
):
Frame
.
__init__
(
self
,
master
)
Frame
.
__init__
(
self
,
master
)
...
...
Demo/tkinter/matt/subclass-existing-widgets.py
View file @
21891d60
...
@@ -11,22 +11,18 @@ class New_Button(Button):
...
@@ -11,22 +11,18 @@ class New_Button(Button):
def
createWidgets
(
top
):
def
createWidgets
(
top
):
f
=
Frame
(
top
)
f
=
Frame
(
top
)
f
.
pack
()
f
.
pack
()
f
.
QUIT
=
Button
(
f
,
{
'text'
:
'QUIT'
,
f
.
QUIT
=
Button
(
f
,
text
=
'QUIT'
,
foreground
=
'red'
,
command
=
top
.
quit
)
'fg'
:
'red'
,
'command'
:
top
.
quit
})
f
.
QUIT
.
pack
({
'side'
:
'left'
,
'fill'
:
'both'
})
f
.
QUIT
.
pack
(
side
=
LEFT
,
fill
=
BOTH
)
# a hello button
# a hello button
f
.
hi_there
=
New_Button
(
f
,
{
'text'
:
'Hello'
}
)
f
.
hi_there
=
New_Button
(
f
,
text
=
'Hello'
)
# we do this on a different line because we need to reference f.hi_there
# we do this on a different line because we need to reference f.hi_there
f
.
hi_there
.
config
(
{
'command'
:
f
.
hi_there
.
callback
}
)
f
.
hi_there
.
config
(
command
=
f
.
hi_there
.
callback
)
f
.
hi_there
.
pack
(
{
'side'
:
'left'
}
)
f
.
hi_there
.
pack
(
side
=
LEFT
)
f
.
hi_there
.
counter
=
43
f
.
hi_there
.
counter
=
43
root
=
Tk
()
root
=
Tk
()
createWidgets
(
root
)
createWidgets
(
root
)
root
.
mainloop
()
root
.
mainloop
()
...
...
Demo/tkinter/matt/two-radio-groups.py
View file @
21891d60
...
@@ -19,29 +19,27 @@ from Tkinter import *
...
@@ -19,29 +19,27 @@ from Tkinter import *
def
makePoliticalParties
():
def
makePoliticalParties
(
var
):
# make menu button
# make menu button
Radiobutton_button
=
Menubutton
(
mBar
,
{
'text'
:
'Political Party'
,
Radiobutton_button
=
Menubutton
(
mBar
,
text
=
'Political Party'
,
'underline'
:
0
,
underline
=
0
)
Pack
:
{
'side'
:
'left'
,
Radiobutton_button
.
pack
(
side
=
LEFT
,
padx
=
'2m'
)
'padx'
:
'2m'
}})
# the primary pulldown
# the primary pulldown
Radiobutton_button
.
menu
=
Menu
(
Radiobutton_button
)
Radiobutton_button
.
menu
=
Menu
(
Radiobutton_button
)
Radiobutton_button
.
menu
.
add
(
'radiobutton'
,
{
'label'
:
'Republican'
,
Radiobutton_button
.
menu
.
add_radiobutton
(
label
=
'Republican'
,
'variable'
:
party
,
variable
=
var
,
value
=
1
)
'value'
:
1
})
Radiobutton_button
.
menu
.
add
(
'radiobutton'
,
{
'label'
:
'Democrat'
,
Radiobutton_button
.
menu
.
add
(
'radiobutton'
,
{
'label'
:
'Democrat'
,
'variable'
:
party
,
'variable'
:
var
,
'value'
:
2
})
'value'
:
2
})
Radiobutton_button
.
menu
.
add
(
'radiobutton'
,
{
'label'
:
'Libertarian'
,
Radiobutton_button
.
menu
.
add
(
'radiobutton'
,
{
'label'
:
'Libertarian'
,
'variable'
:
party
,
'variable'
:
var
,
'value'
:
3
})
'value'
:
3
})
party
.
set
(
2
)
var
.
set
(
2
)
# set up a pointer from the file menubutton back to the file menu
# set up a pointer from the file menubutton back to the file menu
Radiobutton_button
[
'menu'
]
=
Radiobutton_button
.
menu
Radiobutton_button
[
'menu'
]
=
Radiobutton_button
.
menu
...
@@ -49,29 +47,26 @@ def makePoliticalParties():
...
@@ -49,29 +47,26 @@ def makePoliticalParties():
return
Radiobutton_button
return
Radiobutton_button
def
makeFlavors
():
def
makeFlavors
(
var
):
# make menu button
# make menu button
Radiobutton_button
=
Menubutton
(
mBar
,
{
'text'
:
'Flavors'
,
Radiobutton_button
=
Menubutton
(
mBar
,
text
=
'Flavors'
,
'underline'
:
0
,
underline
=
0
)
Pack
:
{
'side'
:
'left'
,
Radiobutton_button
.
pack
(
side
=
LEFT
,
padx
=
'2m'
)
'padx'
:
'2m'
}})
# the primary pulldown
# the primary pulldown
Radiobutton_button
.
menu
=
Menu
(
Radiobutton_button
)
Radiobutton_button
.
menu
=
Menu
(
Radiobutton_button
)
Radiobutton_button
.
menu
.
add
(
'radiobutton'
,
{
'label'
:
'Strawberry'
,
Radiobutton_button
.
menu
.
add_radiobutton
(
label
=
'Strawberry'
,
'variable'
:
flavor
,
variable
=
var
,
value
=
'Strawberry'
)
'value'
:
'Strawberry'
})
Radiobutton_button
.
menu
.
add
(
'radiobutton'
,
{
'label'
:
'Chocolate'
,
Radiobutton_button
.
menu
.
add_radiobutton
(
label
=
'Chocolate'
,
'variable'
:
flavor
,
variable
=
var
,
value
=
'Chocolate'
)
'value'
:
'Chocolate'
})
Radiobutton_button
.
menu
.
add
(
'radiobutton'
,
{
'label'
:
'Rocky Road'
,
Radiobutton_button
.
menu
.
add_radiobutton
(
label
=
'Rocky Road'
,
'variable'
:
flavor
,
variable
=
var
,
value
=
'Rocky Road'
)
'value'
:
'Rocky Road'
})
# choose a default
# choose a default
flavo
r
.
set
(
"Chocolate"
)
va
r
.
set
(
"Chocolate"
)
# set up a pointer from the file menubutton back to the file menu
# set up a pointer from the file menubutton back to the file menu
Radiobutton_button
[
'menu'
]
=
Radiobutton_button
.
menu
Radiobutton_button
[
'menu'
]
=
Radiobutton_button
.
menu
...
@@ -82,7 +77,7 @@ def makeFlavors():
...
@@ -82,7 +77,7 @@ def makeFlavors():
def
printStuff
():
def
printStuff
():
print
"party is"
,
party
.
get
()
print
"party is"
,
party
.
get
()
print
"flavor is"
,
flavor
.
get
()
print
"flavor is"
,
flavor
.
get
()
print
""
print
#################################################
#################################################
#### Main starts here ...
#### Main starts here ...
...
@@ -90,27 +85,24 @@ root = Tk()
...
@@ -90,27 +85,24 @@ root = Tk()
# make a menu bar
# make a menu bar
mBar
=
Frame
(
root
,
{
'relief'
:
'raised'
,
mBar
=
Frame
(
root
,
relief
=
RAISED
,
borderwidth
=
2
)
'bd'
:
2
,
mBar
.
pack
(
fill
=
X
)
Pack
:
{
'side'
:
'top'
,
'fill'
:
'x'
}})
# make two application variables,
# make two application variables,
# one to control each radio button set
# one to control each radio button set
party
=
IntVar
()
party
=
IntVar
()
flavor
=
StringVar
()
flavor
=
StringVar
()
Radiobutton_button
=
makePoliticalParties
()
Radiobutton_button
=
makePoliticalParties
(
party
)
Radiobutton_button2
=
makeFlavors
()
Radiobutton_button2
=
makeFlavors
(
flavor
)
# finally, install the buttons in the menu bar.
# finally, install the buttons in the menu bar.
# This allows for scanning from one menubutton to the next.
# This allows for scanning from one menubutton to the next.
mBar
.
tk_menuBar
(
Radiobutton_button
,
Radiobutton_button2
)
mBar
.
tk_menuBar
(
Radiobutton_button
,
Radiobutton_button2
)
b
=
Button
(
root
,
{
"text"
:
"print party and flavor"
,
b
=
Button
(
root
,
text
=
"print party and flavor"
,
foreground
=
"red"
,
"command"
:
printStuff
,
command
=
printStuff
)
"fg"
:
"red"
})
b
.
pack
(
side
=
TOP
)
b
.
pack
({
"side"
:
"top"
})
root
.
title
(
'menu demo'
)
root
.
title
(
'menu demo'
)
root
.
iconname
(
'menu demo'
)
root
.
iconname
(
'menu demo'
)
...
...
Demo/tkinter/matt/window-creation-more.py
View file @
21891d60
from
Tkinter
import
*
from
Tkinter
import
*
# this shows how to create a new window with a button in it that can create new windows
# this shows how to create a new window with a button in it
# that can create new windows
class
Test
(
Frame
):
class
Test
(
Frame
):
def
printit
(
self
):
def
printit
(
self
):
...
@@ -8,24 +9,21 @@ class Test(Frame):
...
@@ -8,24 +9,21 @@ class Test(Frame):
def
makeWindow
(
self
):
def
makeWindow
(
self
):
fred
=
Toplevel
()
fred
=
Toplevel
()
fred
.
label
=
Button
(
fred
,
{
'text'
:
"This is window number "
+
`self.windownum`
+
"."
,
fred
.
label
=
Button
(
fred
,
'command'
:
self
.
makeWindow
})
text
=
"This is window number %d."
%
self
.
windownum
,
command
=
self
.
makeWindow
)
fred
.
label
.
pack
()
fred
.
label
.
pack
()
self
.
windownum
=
self
.
windownum
+
1
self
.
windownum
=
self
.
windownum
+
1
def
createWidgets
(
self
):
def
createWidgets
(
self
):
self
.
QUIT
=
Button
(
self
,
{
'text'
:
'QUIT'
,
self
.
QUIT
=
Button
(
self
,
text
=
'QUIT'
,
foreground
=
'red'
,
'fg'
:
'red'
,
command
=
self
.
quit
)
'command'
:
self
.
quit
})
self
.
QUIT
.
pack
(
side
=
LEFT
,
fill
=
BOTH
)
self
.
QUIT
.
pack
({
'side'
:
'left'
,
'fill'
:
'both'
})
# a hello button
# a hello button
self
.
hi_there
=
Button
(
self
,
{
'text'
:
'Make a New Window'
,
self
.
hi_there
=
Button
(
self
,
text
=
'Make a New Window'
,
'command'
:
self
.
makeWindow
})
command
=
self
.
makeWindow
)
self
.
hi_there
.
pack
({
'side'
:
'left'
})
self
.
hi_there
.
pack
(
side
=
LEFT
)
def
__init__
(
self
,
master
=
None
):
def
__init__
(
self
,
master
=
None
):
Frame
.
__init__
(
self
,
master
)
Frame
.
__init__
(
self
,
master
)
...
...
Demo/tkinter/matt/window-creation-simple.py
View file @
21891d60
...
@@ -8,22 +8,19 @@ class Test(Frame):
...
@@ -8,22 +8,19 @@ class Test(Frame):
def
makeWindow
(
self
):
def
makeWindow
(
self
):
fred
=
Toplevel
()
fred
=
Toplevel
()
fred
.
label
=
Label
(
fred
,
{
'text'
:
"Here's a new window"
,}
)
fred
.
label
=
Label
(
fred
,
text
=
"Here's a new window"
)
fred
.
label
.
pack
()
fred
.
label
.
pack
()
def
createWidgets
(
self
):
def
createWidgets
(
self
):
self
.
QUIT
=
Button
(
self
,
{
'text'
:
'QUIT'
,
self
.
QUIT
=
Button
(
self
,
text
=
'QUIT'
,
foreground
=
'red'
,
'fg'
:
'red'
,
command
=
self
.
quit
)
'command'
:
self
.
quit
})
self
.
QUIT
.
pack
({
'side'
:
'left'
,
'fill'
:
'both'
})
self
.
QUIT
.
pack
(
side
=
LEFT
,
fill
=
BOTH
)
# a hello button
# a hello button
self
.
hi_there
=
Button
(
self
,
{
'text'
:
'Make a New Window'
,
self
.
hi_there
=
Button
(
self
,
text
=
'Make a New Window'
,
'command'
:
self
.
makeWindow
})
command
=
self
.
makeWindow
)
self
.
hi_there
.
pack
({
'side'
:
'left'
})
self
.
hi_there
.
pack
(
side
=
LEFT
)
def
__init__
(
self
,
master
=
None
):
def
__init__
(
self
,
master
=
None
):
Frame
.
__init__
(
self
,
master
)
Frame
.
__init__
(
self
,
master
)
...
...
Demo/tkinter/matt/window-creation-w-location.py
View file @
21891d60
...
@@ -4,15 +4,15 @@ import sys
...
@@ -4,15 +4,15 @@ import sys
sys
.
path
.
append
(
"/users/mjc4y/projects/python/tkinter/utils"
)
sys
.
path
.
append
(
"/users/mjc4y/projects/python/tkinter/utils"
)
from
TkinterUtils
import
*
from
TkinterUtils
import
*
# this shows how to create a new window with a button in it that can create new windows
# this shows how to create a new window with a button in it that
# can create new windows
class
Test
(
Frame
):
class
Test
(
Frame
):
def
makeWindow
(
self
,
*
args
):
def
makeWindow
(
self
,
*
args
):
fred
=
Toplevel
()
fred
=
Toplevel
()
fred
.
label
=
Canvas
(
fred
,
{
"width"
:
"2i"
,
fred
.
label
=
Canvas
(
fred
,
width
=
"2i"
,
height
=
"2i"
)
"height"
:
"2i"
})
fred
.
label
.
create_line
(
"0"
,
"0"
,
"2i"
,
"2i"
)
fred
.
label
.
create_line
(
"0"
,
"0"
,
"2i"
,
"2i"
)
fred
.
label
.
create_line
(
"0"
,
"2i"
,
"2i"
,
"0"
)
fred
.
label
.
create_line
(
"0"
,
"2i"
,
"2i"
,
"0"
)
...
@@ -22,14 +22,12 @@ class Test(Frame):
...
@@ -22,14 +22,12 @@ class Test(Frame):
def
createWidgets
(
self
):
def
createWidgets
(
self
):
self
.
QUIT
=
QuitButton
(
self
)
self
.
QUIT
=
QuitButton
(
self
)
self
.
QUIT
.
pack
(
{
'side'
:
'left'
,
'fill'
:
'both'
}
)
self
.
QUIT
.
pack
(
side
=
LEFT
,
fill
=
BOTH
)
self
.
makeWindow
=
Button
(
self
,
text
=
'Make a New Window'
,
self
.
makeWindow
=
Button
(
self
,
{
'text'
:
'Make a New Window'
,
width
=
50
,
height
=
20
,
'width'
:
50
,
command
=
self
.
makeWindow
)
'height'
:
20
,
self
.
makeWindow
.
pack
(
side
=
LEFT
)
'command'
:
self
.
makeWindow
})
self
.
makeWindow
.
pack
({
'side'
:
'left'
})
def
__init__
(
self
,
master
=
None
):
def
__init__
(
self
,
master
=
None
):
Frame
.
__init__
(
self
,
master
)
Frame
.
__init__
(
self
,
master
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment