|
1 from 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 |
|
8 class 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 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) |
|
21 |
|
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")) |
|
27 |
|
28 self.draw.scrollX = Scrollbar(self, orient=HORIZONTAL) |
|
29 self.draw.scrollY = Scrollbar(self, orient=VERTICAL) |
|
30 |
|
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 |
|
36 |
|
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") |
|
41 |
|
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) |
|
46 |
|
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 |
|
58 test = Test() |
|
59 |
|
60 test.mainloop() |