-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()