2014-10-19 92 views
1

所以我有一個小問題在tk(python,代碼如下),問題是我的滾動條似乎沒有鏈接到我的畫布,但我想我問了它。任何提示?Python中的滾動窗口小部件在tk

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

畫布滾動條只會滾動添加到畫布的小部件,並帶有create_window。它將而不是添加到畫布上的滾動小部件與pack,placegrid