ยปCore Development>Code coverage>Demo/tkinter/matt/canvas-with-scrollbars.py

Python code coverage for Demo/tkinter/matt/canvas-with-scrollbars.py

#countcontent
1n/afrom tkinter import *
2n/a
3n/a# This example program creates a scroling canvas, and demonstrates
4n/a# how to tie scrollbars and canvses together. The mechanism
5n/a# is analogus for listboxes and other widgets with
6n/a# "xscroll" and "yscroll" configuration options.
7n/a
8n/aclass Test(Frame):
9n/a def printit(self):
10n/a print("hi")
11n/a
12n/a def createWidgets(self):
13n/a self.question = Label(self, text="Can Find The BLUE Square??????")
14n/a self.question.pack()
15n/a
16n/a self.QUIT = Button(self, text='QUIT', background='red',
17n/a height=3, command=self.quit)
18n/a self.QUIT.pack(side=BOTTOM, fill=BOTH)
19n/a spacer = Frame(self, height="0.25i")
20n/a spacer.pack(side=BOTTOM)
21n/a
22n/a # notice that the scroll region (20" x 20") is larger than
23n/a # displayed size of the widget (5" x 5")
24n/a self.draw = Canvas(self, width="5i", height="5i",
25n/a background="white",
26n/a scrollregion=(0, 0, "20i", "20i"))
27n/a
28n/a self.draw.scrollX = Scrollbar(self, orient=HORIZONTAL)
29n/a self.draw.scrollY = Scrollbar(self, orient=VERTICAL)
30n/a
31n/a # now tie the three together. This is standard boilerplate text
32n/a self.draw['xscrollcommand'] = self.draw.scrollX.set
33n/a self.draw['yscrollcommand'] = self.draw.scrollY.set
34n/a self.draw.scrollX['command'] = self.draw.xview
35n/a self.draw.scrollY['command'] = self.draw.yview
36n/a
37n/a # draw something. Note that the first square
38n/a # is visible, but you need to scroll to see the second one.
39n/a self.draw.create_rectangle(0, 0, "3.5i", "3.5i", fill="black")
40n/a self.draw.create_rectangle("10i", "10i", "13.5i", "13.5i", fill="blue")
41n/a
42n/a # pack 'em up
43n/a self.draw.scrollX.pack(side=BOTTOM, fill=X)
44n/a self.draw.scrollY.pack(side=RIGHT, fill=Y)
45n/a self.draw.pack(side=LEFT)
46n/a
47n/a
48n/a def scrollCanvasX(self, *args):
49n/a print("scrolling", args)
50n/a print(self.draw.scrollX.get())
51n/a
52n/a
53n/a def __init__(self, master=None):
54n/a Frame.__init__(self, master)
55n/a Pack.config(self)
56n/a self.createWidgets()
57n/a
58n/atest = Test()
59n/a
60n/atest.mainloop()