blob: fcbcd151a62a9a14ac97a6b51591c493174b3158 [file] [log] [blame]
Guido van Rossum35820f71994-10-07 09:55:26 +00001from Tkinter import *
2
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.
7
8class Test(Frame):
9 def printit(self):
10 print "hi"
11
12 def createWidgets(self):
13 self.question = Label(self, {"text": "Can Find The BLUE Square??????",
14 Pack : {"side" : "top"}})
15
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"}})
23
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"})
30
31
32 self.draw.scrollX = Scrollbar(self, {"orient" : "horizontal"})
33 self.draw.scrollY = Scrollbar(self, {"orient" : "vertical"})
34
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
40
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")
45
46
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'})
53
54
55 def scrollCanvasX(self, *args):
56 print "scrolling", args
57 print self.draw.scrollX.get()
58
59
60 def __init__(self, master=None):
61 Frame.__init__(self, master)
62 Pack.config(self)
63 self.createWidgets()
64
65test = Test()
66
67test.mainloop()