2017-08-07 55 views
1

工作在MacOS塞拉利昂,与py2.7.13和py3.6,Tkinter的填充= Y不与巴顿

我期待下面的代码看起来像: enter image description here

import Tkinter as tk 
root = tk.Tk() 
tk.Button(root, text="A").pack(side=tk.LEFT, expand=tk.YES, fill=tk.Y) 
tk.Button(root, text="B").pack(side=tk.TOP, expand=tk.YES, fill=tk.BOTH) 
tk.Button(root, text="C").pack(side=tk.RIGHT, expand=tk.YES, fill=tk.NONE, anchor = tk.NE) 
tk.Button(root, text="D").pack(side=tk.LEFT, expand=tk.NO, fill=tk.Y) 
tk.Button(root, text="E").pack(side=tk.TOP, expand=tk.NO, fill=tk.BOTH) 
tk.Button(root, text="F").pack(side=tk.RIGHT, expand=tk.NO, fill=tk.NONE) 
tk.Button(root, text="G").pack(side=tk.BOTTOM, expand=tk.YES, fill=tk.Y) 
tk.Button(root, text="H").pack(side=tk.TOP, expand=tk.NO, fill=tk.BOTH) 
tk.Button(root, text="I").pack(side=tk.RIGHT, expand=tk.NO) 
tk.Button(root, text="J").pack(anchor=tk.SE) 
root.mainloop() 

,但得到 enter image description here

所以那些fill = Y的按钮没有展开和垂直填充。

然而,标签像预期的那样: enter image description here

与代码:

import Tkinter as tk 
root = tk.Tk() 
tk.Label(root, text="A", bg='green').pack(side=tk.LEFT, expand=tk.YES, fill=tk.Y) 
tk.Label(root, text="B", bg='red').pack(side=tk.TOP, expand=tk.YES, fill=tk.BOTH) 
tk.Label(root, text="C", bg='blue').pack(side=tk.RIGHT, expand=tk.YES, fill=tk.NONE, anchor=tk.NE) 
tk.Label(root, text="D", bg='yellow').pack(side=tk.LEFT, expand=tk.NO, fill=tk.Y) 
tk.Label(root, text="E", bg='purple').pack(side=tk.TOP, expand=tk.NO, fill=tk.BOTH) 
tk.Label(root, text="F", bg='pink').pack(side=tk.TOP, expand=tk.NO, fill=tk.NONE) 
tk.Label(root, text="G", bg='green').pack(side=tk.BOTTOM, expand=tk.YES, fill=tk.Y) 
tk.Label(root, text="H", bg='red').pack(side=tk.TOP, expand=tk.NO, fill=tk.BOTH) 
tk.Label(root, text="I", bg='blue').pack(side=tk.RIGHT, expand=tk.NO) 
tk.Label(root, text="J", bg='yellow').pack(anchor=tk.SE) 
root.mainloop() 

缺少什么我在这里?按钮的设计与标签行为不同吗?

回答