3 # This example program creates a scroling canvas, and demonstrates
4 # how to tie scrollbars and canvses together. The mechanism
5 # is analogus for listboxes and other widgets with
6 # "xscroll" and "yscroll" configuration options.
12 def createWidgets(self
):
13 self
.question
= Label(self
, {"text": "Can Find The BLUE Square??????",
14 Pack
: {"side" : "top"}})
16 self
.QUIT
= Button(self
, {'text': 'QUIT',
19 'command': self
.quit
})
20 self
.QUIT
.pack({'side': 'bottom', 'fill': 'both'})
21 spacer
= Frame(self
, {"height" : "0.25i",
22 Pack
: {"side" : "bottom"}})
24 # notice that the scroll region (20" x 20") is larger than
25 # displayed size of the widget (5" x 5")
26 self
.draw
= Canvas(self
, {"width" : "5i",
29 "scrollregion" : "0i 0i 20i 20i"})
32 self
.draw
.scrollX
= Scrollbar(self
, {"orient" : "horizontal"})
33 self
.draw
.scrollY
= Scrollbar(self
, {"orient" : "vertical"})
35 # now tie the three together. This is standard boilerplate text
36 self
.draw
['xscroll'] = self
.draw
.scrollX
.set
37 self
.draw
['yscroll'] = self
.draw
.scrollY
.set
38 self
.draw
.scrollX
['command'] = self
.draw
.xview
39 self
.draw
.scrollY
['command'] = self
.draw
.yview
41 # draw something. Note that the first square
42 # is visible, but you need to scroll to see the second one.
43 self
.draw
.create_polygon("0i", "0i", "3.5i", "0i", "3.5i", "3.5i", "0i" , "3.5i")
44 self
.draw
.create_polygon("10i", "10i", "13.5i", "10i", "13.5i", "13.5i", "10i" , "13.5i", "-fill", "blue")
48 self
.draw
.scrollX
.pack({'side': 'bottom',
50 self
.draw
.scrollY
.pack({'side': 'right',
52 self
.draw
.pack({'side': 'left'})
55 def scrollCanvasX(self
, *args
):
56 print "scrolling", args
57 print self
.draw
.scrollX
.get()
60 def __init__(self
, master
=None):
61 Frame
.__init
__(self
, master
)