2016-07-18 86 views
1

應該怎樣做有left_margin青色)和right_margin品紅)框架把所有的垂直高度從top_marginbottom_margin模擬上,下,左,在Tkinter的包幾何右頁邊距

import Tkinter as tk 

root = tk.Tk() 

top_margin = tk.Frame(root, height=32, background='red') 
left_margin = tk.Frame(root, background='cyan') 
sheet_area = tk.Frame(root, background='white') 
right_margin = tk.Frame(root, background='magenta') 
bottom_margin = tk.Frame(root, height=32, background='blue') 

top_margin.pack(side=tk.TOP, expand=tk.YES, fill=tk.X, anchor=tk.N) 
bottom_margin.pack(side=tk.BOTTOM, expand=tk.YES, fill=tk.X, anchor=tk.S) 
left_margin.pack(side=tk.LEFT, expand=tk.YES, fill=tk.BOTH) 
right_margin.pack(side=tk.RIGHT, expand=tk.YES, fill=tk.BOTH) 

root.mainloop() 

回答

1

所以我想我知道你的問題是什麼。您正在打包左側和右側之前的頂部和底部邊距。沒有爲邊距設置任何特定的大小。

如果你改變你的包語句是這樣的:

left_margin.pack(side=tk.LEFT, expand=tk.YES, fill=tk.BOTH) 
right_margin.pack(side=tk.RIGHT, expand=tk.YES, fill=tk.BOTH) 
top_margin.pack(side=tk.TOP, expand=tk.YES, fill=tk.X, anchor=tk.N) 
bottom_margin.pack(side=tk.BOTTOM, expand=tk.YES, fill=tk.X, anchor=tk.S) 

如果你想在頂部和底部邊緣可見添加一個寬度爲好。像這樣:

bottom_margin = tk.Frame(root, width = 10, height=32, background='blue') 
top_margin = tk.Frame(root, width = 10, height=32, background='red') 

希望這會解決你的問題:)

相關問題