Python tkinter滚动框,在画布中展开LabelFrame

2024-09-29 23:15:56 发布

您现在位置:Python中文网/ 问答频道 /正文

再见。我有一个滚动框的问题。我用现成的溶液(http://efffbot.org/zone/tkinter-autoscrollbar.htm)在

但是我不知道如何在窗口扩展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()

Tags: selfmastercolumnrootgridrowcanvasweight
1条回答
网友
1楼 · 发布于 2024-09-29 23:15:56

创建为画布对象的窗口必须告知其宽度,如果您希望它们不是其自然大小。在

最常见的方法是绑定到画布的<Configure>事件,每当画布的大小发生变化时(例如第一次绘制画布时,或用户调整窗口大小时),都会调用该事件。很明显,你可以在画布的边距上迭代,然后设置所有控件的边距。在

相关问题 更多 >

    热门问题