Python 34填充tkinter中可滚动框架的宽度

时间:2015-03-16 04:54:08

标签: user-interface python-3.x tkinter

这是我的代码:

from tkinter import *
import textwrap

GUI = Tk()
note_frame = Frame(GUI)
note_frame.grid(row=0, column=0)
note_scrollbar = Scrollbar(note_frame)
note_scrollbar.pack(side=RIGHT, fill=Y)
note_container = Canvas(note_frame, yscrollcommand = note_scrollbar.set)
note_container.pack()
note_scrollbar.config(command=note_container.yview)
def configure_note_container(event):
    note_container.config(scrollregion=note_container.bbox("all"), 
                width=200, height=200)
note_list = Frame(note_container, width=200, height=200)
note_container.create_window((0,0), window=note_list, anchor='nw')
note_list.bind("<Configure>", configure_note_container)
for x in range(100):
    exec(textwrap.dedent(
                """
                label_{0} = Label(note_list, text='{0}', bg="white")
                label_{0}.grid(column=0, row={0})
                """.format(x)))

GUI.mainloop()

我试图让标签拉伸以填充框架内的网格单元格的X宽度(这是在画布内,以便我可以使用滚动条),但我不知道如何这样做 - 当note_container配置好后,它似乎取消了任何大小调整。 grid_propagate似乎也不起作用。

感谢任何帮助。感谢。

0 个答案:

没有答案
相关问题