我试图获得相当于底部的红色框(在我的真实程序中它是标签和复选框)以扩展到顶部绿色框的大小(这也是我真实程序中的复选框)。填充和扩展似乎都无法正常工作。我也不能改变宽度。我做错了什么?
try:
from tkinter import *
except ImportError:
from Tkinter import *
class Application(Frame):
def __init__(self,master=None):
root = Tk()
Frame.__init__(self,master)
topframe = Frame(self)
botframe = Frame(self)
Frame(topframe, background="green", width=300, height = 200).grid(row =0, column = 0)
Frame(botframe, background="red", width=200, height = 200).grid(row =1, column = 0, sticky = E)
topframe.pack(side = TOP)
botframe.pack(side = BOTTOM, fill = BOTH, expand = True)
self.pack(fill="both", expand=True)
root.mainloop()
Application()
答案 0 :(得分:0)
我修好了,看看你是否有类似的问题
try:
from tkinter import *
except ImportError:
from Tkinter import *
class Application(Frame):
def __init__(self,master=None):
root = Tk()
Frame.__init__(self,master)
topframe = Frame(root)
botframe = Frame(root)
topframe.grid(row =0, column = 0, sticky=N+E+W)
botframe.grid(row =1, column = 0, sticky=S+E+W)
topframe.columnconfigure(0, weight=1)
botframe.columnconfigure(0, weight=1)
Frame(topframe, background="green", width=300, height = 200).grid(row =0, column = 0, sticky=N+E+W)
Frame(botframe, background="red", width=200, height = 200).grid(row =1, column = 0, sticky = S+E+W)
root.mainloop()
Application()
答案 1 :(得分:0)
当您使用网格时,一条经验法则是您应grid_rowconfigure
和grid_columnconfigure
为至少一行和一列提供非零权重。这将导致该行和该列在布局中“占用空间”。