changes by Barry, e.g. font lock & email addresses
[python/dscho.git] / Demo / tkinter / matt / canvas-with-scrollbars.py
blobfcbcd151a62a9a14ac97a6b51591c493174b3158
1 from Tkinter import *
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.
8 class Test(Frame):
9 def printit(self):
10 print "hi"
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',
17 'bg': 'red',
18 "height" : "3",
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",
27 "height" : "5i",
28 "bg" : "white",
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")
47 # pack 'em up
48 self.draw.scrollX.pack({'side': 'bottom',
49 "fill" : "x"})
50 self.draw.scrollY.pack({'side': 'right',
51 "fill" : "y"})
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)
62 Pack.config(self)
63 self.createWidgets()
65 test = Test()
67 test.mainloop()