2012-03-18 54 views
-1

美好的一天。我有一个滚动框架的问题。我使用现成的解决方案(http://effbot.org/zone/tkinter-autoscrollbar.htm)Python tkinter滚动框架,展开canvas中的LabelFrame

但我不知道如何通过窗口扩展LabelFrame(“kontakty”)?借口创建为画布对象必须被告知有多宽,如果你希望他们比他们的自然大小等我的英语

#prevzato z http://effbot.org/zone/tkinter-autoscrollbar.htm 

from Tkinter import * 

class AutoScrollbar(Scrollbar): 
    # a scrollbar that hides itself if it's not needed. only 
    # works if you use the grid geometry manager. 
def set(self, lo, hi): 
    if float(lo) <= 0.0 and float(hi) >= 1.0: 
     # grid_remove is currently missing from Tkinter! 
     self.tk.call("grid", "remove", self) 
    else: 
     self.grid() 
    Scrollbar.set(self, lo, hi) 
def pack(self, **kw): 
    raise TclError, "cannot use pack with this widget" 
def place(self, **kw): 
    raise TclError, "cannot use place with this widget" 

root = Tk() 


master = Frame(root) 
master.grid(row=0, column=0, sticky=N+S+E+W) 


vscrollbar = AutoScrollbar(master) 
vscrollbar.grid(row=0, column=1, sticky=N+S) 
hscrollbar = AutoScrollbar(master, orient=HORIZONTAL) 
hscrollbar.grid(row=1, column=0, sticky=E+W) 

master.rowconfigure(0, weight=1) 
master.columnconfigure(0, weight=1) 

root.rowconfigure(0, weight=1) 
root.columnconfigure(0, weight=1) 



canvas = Canvas(master, 
      yscrollcommand=vscrollbar.set, 
      xscrollcommand=hscrollbar.set, bg = "red", width = 200, height = 400) 
canvas.grid(row=0, column=0, sticky=N+S+E+W) 

canvas.rowconfigure(0, weight=1) 
canvas.columnconfigure(0, weight=1) 

vscrollbar.config(command=canvas.yview) 
hscrollbar.config(command=canvas.xview) 

# make the canvas expandable 
root.grid_rowconfigure(0, weight=1) 
root.grid_columnconfigure(0, weight=1) 

# 
# create canvas contents 

kontakty = LabelFrame(canvas, width = 600, height =400, text = "Skupina") 
kontakty.grid(row=0, column=0, sticky=N+S+E+W) 

kontakty.rowconfigure(0, weight=1) 
kontakty.columnconfigure(0, weight=1) 



canvas.create_window(0, 0, anchor=NW, window=kontakty) 

kontakty.update_idletasks() 

canvas.config(scrollregion=canvas.bbox("all")) 

root.mainloop() 

回答

0

窗口。

执行此操作的最常见方法是绑定到画布的<Configure>事件,每次画布大小发生变化时(例如第一次绘制时或用户调整窗口大小时)都会调用此事件。然后,您可以查询画布的大小,然后遍历所有嵌入的小部件,并将它们的大小设置为画布的宽度(显然,减去所需的任何边框或边距)。