我有以下设置。
根窗口。
在这个根窗口中,我有前3行(0-2)的按钮和标签。这一切都很好。
下面我使用了一个框架,其中包含一个画布,一个滚动条和另一个填充了一堆标签和按钮的框架。这一切都有效。
但我不知道如何使画布或框架延伸到屏幕底部。(黑色区域)。我试过玩粘性的,也有网格的,但我不明白需要什么安排。如能提供解决方案和解释,将不胜感激!
注意:前0-2行不会显示任何内容,因为下面的代码运行不包括按钮和标签小部件。但我需要的是将黑色区域扩展到根窗口的底部。我相信解决方案将独立于填充小部件
enter image description here
这是我的密码。
import tkinter as tk
class GUI(tk.Tk):
NUM_COLS = 12
ROWSB4TABLE = 3
TABLESTARTROW = ROWSB4TABLE + 1
def __init__(self):
super().__init__()
self.title("Test")
self.geometry("1000x500")
self.resizable(True, True)
self.grid_columnconfigure(0, weight=2, uniform='col')
self.grid_columnconfigure(1, weight=2, uniform='col')
self.grid_columnconfigure(2, weight=2, uniform='col')
self.grid_columnconfigure(3, weight=2, uniform='col')
self.grid_columnconfigure(4, weight=2, uniform='col')
self.grid_columnconfigure(5, weight=2, uniform='col')
self.grid_columnconfigure(6, weight=2, uniform='col')
self.grid_columnconfigure(7, weight=2, uniform='col')
self.grid_columnconfigure(8, weight=1, uniform='col')
self.grid_columnconfigure(9, weight=1, uniform='col')
self.grid_columnconfigure(10, weight=1, uniform='col')
self.grid_columnconfigure(11, weight=1, uniform='col')
self.grid_rowconfigure(0, weight=0, uniform='row')
self.grid_rowconfigure(1, weight=0, uniform='row')
self.grid_rowconfigure(2, weight=0, uniform='row')
self.frame_canvas = tk.Frame(self)
self.frame_canvas.grid(row=self.TABLESTARTROW, column=0, sticky=tk.EW, columnspan=self.NUM_COLS)
self.frame_canvas.grid_rowconfigure(0, weight=1)
self.frame_canvas.grid_columnconfigure(0, weight=1)
self.canvas = tk.Canvas(self.frame_canvas, bg="black")
self.canvas.grid(row=0, column=0, sticky=tk.EW)
vsb = tk.Scrollbar(self.frame_canvas, orient="vertical", command=self.canvas.yview)
vsb.grid(row=0, column=12, sticky='ns')
self.canvas.configure(yscrollcommand=vsb.set)
self.tableframe = tk.Frame(self.canvas, bg='Black')
self.canvas.create_window((0,0), window=self.tableframe, anchor=tk.NW)
self.tableframe.grid_columnconfigure(0, weight=2, uniform='coltf')
self.tableframe.grid_columnconfigure(1, weight=2, uniform='coltf')
self.tableframe.grid_columnconfigure(2, weight=2, uniform='coltf')
self.tableframe.grid_columnconfigure(3, weight=2, uniform='coltf')
self.tableframe.grid_columnconfigure(4, weight=2, uniform='coltf')
self.tableframe.grid_columnconfigure(5, weight=2, uniform='coltf')
self.tableframe.grid_columnconfigure(6, weight=2, uniform='coltf')
self.tableframe.grid_columnconfigure(7, weight=2, uniform='coltf')
self.tableframe.grid_columnconfigure(8, weight=1, uniform='coltf')
self.tableframe.grid_columnconfigure(9, weight=1, uniform='coltf')
self.tableframe.grid_columnconfigure(10, weight=1, uniform='coltf')
self.tableframe.grid_columnconfigure(11, weight=1, uniform='coltf')
if __name__ == "__main__":
app = GUI()
app.mainloop()