blob: 60c7b132ea06b702bfbdbe88d2ae043149516eb3 [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):
Guido van Rossum89cb67b1996-07-30 18:57:18 +000013 self.question = Label(self, text="Can Find The BLUE Square??????")
14 self.question.pack()
15
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)
Guido van Rossum35820f71994-10-07 09:55:26 +000021
22 # notice that the scroll region (20" x 20") is larger than
23 # displayed size of the widget (5" x 5")
Guido van Rossum89cb67b1996-07-30 18:57:18 +000024 self.draw = Canvas(self, width="5i", height="5i",
25 background="white",
26 scrollregion=(0, 0, "20i", "20i"))
Guido van Rossum35820f71994-10-07 09:55:26 +000027
Guido van Rossum89cb67b1996-07-30 18:57:18 +000028 self.draw.scrollX = Scrollbar(self, orient=HORIZONTAL)
29 self.draw.scrollY = Scrollbar(self, orient=VERTICAL)
Guido van Rossum35820f71994-10-07 09:55:26 +000030
31 # now tie the three together. This is standard boilerplate text
Guido van Rossum447ae531995-10-08 00:41:25 +000032 self.draw['xscrollcommand'] = self.draw.scrollX.set
33 self.draw['yscrollcommand'] = self.draw.scrollY.set
Guido van Rossum35820f71994-10-07 09:55:26 +000034 self.draw.scrollX['command'] = self.draw.xview
35 self.draw.scrollY['command'] = self.draw.yview
36
37 # draw something. Note that the first square
38 # is visible, but you need to scroll to see the second one.
Guido van Rossum89cb67b1996-07-30 18:57:18 +000039 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")
Guido van Rossum35820f71994-10-07 09:55:26 +000041
Guido van Rossum35820f71994-10-07 09:55:26 +000042 # pack 'em up
Guido van Rossum89cb67b1996-07-30 18:57:18 +000043 self.draw.scrollX.pack(side=BOTTOM, fill=X)
44 self.draw.scrollY.pack(side=RIGHT, fill=Y)
45 self.draw.pack(side=LEFT)
Guido van Rossum35820f71994-10-07 09:55:26 +000046
47
48 def scrollCanvasX(self, *args):
49 print "scrolling", args
50 print self.draw.scrollX.get()
51
52
53 def __init__(self, master=None):
54 Frame.__init__(self, master)
55 Pack.config(self)
56 self.createWidgets()
57
58test = Test()
59
60test.mainloop()