tk中的Python可滚动小部件

时间:2014-10-19 19:49:11

标签: python tkinter tk

所以我在tk(python,下面的代码)中有一个gui的小问题,问题是我的滚动条似乎没有链接到我的画布,虽然我想我正确地问了......任何提示?< / p>

root = tk.Tk()  # window
root_frame = tk.Frame(root) # main container
root_frame.pack()

container_frame = tk.Frame(root_frame)  # specific container
container_frame.pack(fill="both")

inner_canvas = tk.Canvas(container_frame, width=100, height=100)  # contains the widgets
inner_canvas.grid_propagate(False)  # i heard this is necessary ...
inner_scrollbar = tk.Scrollbar(container_frame, command=inner_canvas.yview)
inner_canvas.configure(yscrollcommand=inner_scrollbar.set)
inner_canvas.pack(fill="both", side="left")
inner_scrollbar.pack(fill="y", side="right")
for k in range(100):  # simulate the homemade widgets i want to add.
    tk.Label(inner_canvas, text=str(k)+" row").grid(row=k, rowspan=1, columnspan=1)

root.mainloop()

1 个答案:

答案 0 :(得分:1)

画布滚动条仅滚动使用create_window添加到画布的小部件。它将使用packplacegrid滚动添加到画布的小部件。