例えば、こういうことでしょうかね
python3
1
2#ウィンドウのスクロールバーの作成
3
4from tkinter import *
5
6
7class VerticalScrolledFrame(Frame):
8 """A pure Tkinter scrollable frame that actually works!
9 * Use the 'interior' attribute to place widgets inside the scrollable frame
10 * Construct and pack/place/grid normally
11 * This frame only allows vertical scrolling
12
13 """
14 def __init__(self, parent, *args, **kw):
15 Frame.__init__(self, parent, *args, **kw)
16
17 # スクロールバーの作成
18 vscrollbar = Scrollbar(self, orient=VERTICAL)
19 vscrollbar.pack(fill=Y, side=RIGHT, expand=FALSE)
20 canvas = Canvas(self, bd=0, highlightthickness=0,
21 yscrollcommand=vscrollbar.set)
22 canvas.pack(side=LEFT, fill=BOTH, expand=TRUE)
23 vscrollbar.config(command=canvas.yview)
24
25 # ビューをリセット
26 canvas.xview_moveto(0)
27 canvas.yview_moveto(0)
28
29 # create a frame inside the canvas which will be scrolled with it
30 self.interior = interior = Frame(canvas)
31 interior_id = canvas.create_window(0, 0, window=interior,
32 anchor=NW)
33
34 # track changes to the canvas and frame width and sync them,
35 # also updating the scrollbar
36 def _configure_interior(event):
37 # update the scrollbars to match the size of the inner frame
38 size = (interior.winfo_reqwidth(), interior.winfo_reqheight())
39 canvas.config(scrollregion="0 0 %s %s" % size)
40 if interior.winfo_reqwidth() != canvas.winfo_width():
41 # update the canvas's width to fit the inner frame
42 canvas.config(width=interior.winfo_reqwidth())
43 interior.bind('<Configure>', _configure_interior)
44
45 def _configure_canvas(event):
46 if interior.winfo_reqwidth() != canvas.winfo_width():
47 # update the inner frame's width to fill the canvas
48 canvas.itemconfigure(interior_id, width=canvas.winfo_width())
49 canvas.bind('<Configure>', _configure_canvas)
50
51
52if __name__ == "__main__":
53
54 class SampleApp(Tk):
55 def __init__(self, *args, **kwargs):
56 root = Tk.__init__(self, *args, **kwargs)
57
58
59 self.frame = VerticalScrolledFrame(root)
60 self.frame.pack()
61 self.label = Label(text="ウィンドウを縮めてみてください。スクロールバーが出てきます.")
62 self.label.pack()
63 buttons = []
64 for i in range(20):
65 buttons.append(Button(self.frame.interior, text="Button " + str(i)))
66 buttons[-1].pack()
67
68 app = SampleApp()
69 app.mainloop()
70
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。