我想显示2帧和一个画布,以便:
我没有得到预期的结果。这是我的代码:
from Tkinter import *
class Mine(Frame):
def __init__(self,master):
Frame.__init__(self,master)
self.frameh()
self.framev()
self.thecanvas()
# horizontal frame on top spanning over 2 columns
def frameh(self):
self.fh=Frame(root,width=400,height=40,bg="red")
self.fh.grid(sticky=N,row=0,columnspan=2)
# vertical frame on bottom
def framev(self):
self.fv=Frame(root,height=200,bg="blue")
self.fv.grid(sticky=S+W,row=1,column=0)
def thecanvas(self):
self.c=Canvas(root,width=500,height=200,bg="black")
self.c.grid(sticky=S+E,row=1,column=1)
if __name__=="__main__":
root=Tk()
root.wm_title("mine")
m=Mine(root)
root.mainloop()
答案 0 :(得分:2)
我认为您要为columnspan=2
设置frameh
,以便它跨越framev
和thecanvas
列(加上额外sticky
来制作它填充整个宽度),并为framev
定义非零的最小宽度:
...
def frameh(self):
self.fh=Frame(root, width=400, height=40, bg="red")
self.fh.grid(sticky=N+E+W, row=0, columnspan=2)
def framev(self):
self.fv=Frame(root, height=200, width=100, bg="blue")
self.fv.grid(sticky=S+W, row=1, column=0)
...
这给了我: