Issue
Is it possible to specify where to apply the padding in Python Tkinter - like in CSS, there is margin-[top|right|bottom|left]
?
There is pady
but it inserts space both top and bottom. Same for padx
, both left and right.
Solution
If you are using a ttk
widget, you also have the option of setting the padding
in the constructor for most widgets, which is synonymous with the ipadx
, and ipady
options.
It accepts the following patterns:
ttk.Button(padding=(5, 10, 5, 10)) # (left, right, top, bottom)
ttk.Button(padding=((5, 10), (5, 10))) # ((left, right), (top, bottom))
ttk.Button(padding=(5, 10)) # (left/right, top/bottom)
ttk.Button(padding=5) # left/right/top/bottom
For padx
and pady
, the following patterns are acceptable:
padx=(5, 10) # (left, right)
padx=5 # left & right
pady=(5, 10) # (top, bottom)
pady=5 # top & bottom
Answered By - idryer
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.