This should finally fix #6896. Let's watch the buildbots.
[python.git] / Demo / tkinter / matt / canvas-with-scrollbars.py
blob81ef25a88a21c0ff7b59d4a1881ad3df9d67d985
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 self.question.pack()
16 self.QUIT = Button(self, text='QUIT', background='red',
17 height=3, command=self.quit)
18 self.QUIT.pack(side=BOTTOM, fill=BOTH)
19 spacer = Frame(self, height="0.25i")
20 spacer.pack(side=BOTTOM)
22 # notice that the scroll region (20" x 20") is larger than
23 # displayed size of the widget (5" x 5")
24 self.draw = Canvas(self, width="5i", height="5i",
25 background="white",
26 scrollregion=(0, 0, "20i", "20i"))
28 self.draw.scrollX = Scrollbar(self, orient=HORIZONTAL)
29 self.draw.scrollY = Scrollbar(self, orient=VERTICAL)
31 # now tie the three together. This is standard boilerplate text
32 self.draw['xscrollcommand'] = self.draw.scrollX.set
33 self.draw['yscrollcommand'] = self.draw.scrollY.set
34 self.draw.scrollX['command'] = self.draw.xview
35 self.draw.scrollY['command'] = self.draw.yview
37 # draw something. Note that the first square
38 # is visible, but you need to scroll to see the second one.
39 self.draw.create_rectangle(0, 0, "3.5i", "3.5i", fill="black")
40 self.draw.create_rectangle("10i", "10i", "13.5i", "13.5i", fill="blue")
42 # pack 'em up
43 self.draw.scrollX.pack(side=BOTTOM, fill=X)
44 self.draw.scrollY.pack(side=RIGHT, fill=Y)
45 self.draw.pack(side=LEFT)
48 def scrollCanvasX(self, *args):
49 print "scrolling", args
50 print self.draw.scrollX.get()
53 def __init__(self, master=None):
54 Frame.__init__(self, master)
55 Pack.config(self)
56 self.createWidgets()
58 test = Test()
60 test.mainloop()