Tkinter-使小部件适合框架尺寸

时间:2019-12-11 13:30:02

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

我正在尝试将小部件(例如按钮,标签(包括图像))放入框架中。每当我这样做时,框架尺寸都会更改以适合小部件。因此,小部件不会“适合”框架,但是而是扩大框架的大小。

例如参见下图:

enter image description here

我有3张照片:

    root = Tk()

    root.title('Model Definition')
    root.geometry('{}x{}'.format(800, 600))


    frame_1 = Frame(root, bg='red', pady=3)
    frame_2 = Frame(root, bg='green', padx=3, pady=3)
    frame_3 = Frame(root, bg='black', pady=3)


    frame_1.grid(row=0, sticky='nsew')
    frame_2.grid(row=1, sticky='nsew')
    frame_3.grid(row=2, sticky='nsew')


    # All frames expand at the same rate!
    root.grid_rowconfigure(index=0, weight=1)
    root.grid_rowconfigure(index=1, weight=1)
    root.grid_rowconfigure(index=2, weight=1)
    root.grid_columnconfigure(index=0, weight=1)

    root.mainloop()

调整根窗口大小时,每一行的高度均相同。如果我在frame_1上添加图像标签,则框架的高度会扩展以适合它,因此当我扩展根窗口时,它会不成比例地扩展框架的大小。 (请参见下图)

enter image description here

标签是否有符合框架尺寸的方法? (即,将图像放置在帧外的边界内)

0 个答案:

没有答案
相关问题