Jac*_* S. 53 python tkinter padding
如何在没有tkinter中心窗口小部件的情况下向tkinter窗口添加填充?我试过了:
self.canvas_l = Label(self.master, text="choose a color:", font="helvetica 12")
self.canvas_l.grid(row=9, column=1, sticky=S, ipady=30)
Run Code Online (Sandbox Code Playgroud)
和
self.canvas_l = Label(self.master, text="choose a color:", font="helvetica 12")
self.canvas_l.grid(row=9, column=1, rowspan=2, sticky=S, pady=30)
Run Code Online (Sandbox Code Playgroud)
我只想在标签的顶部添加30px填充.
Bry*_*ley 138
填充选项padx和pady可以采取2元组表示左/右和上/下填充.
这是一个例子:
import tkinter as tk
class MyApp():
def __init__(self):
self.root = tk.Tk()
l1 = tk.Label(self.root, text="Hello")
l2 = tk.Label(self.root, text="World")
l1.grid(row=0, column=0, padx=(100, 10))
l2.grid(row=1, column=0, padx=(10, 100))
app = MyApp()
app.root.mainloop()
Run Code Online (Sandbox Code Playgroud)
有多种方法可以使用place或grid甚至该pack方法。
示例代码:
from tkinter import *
root = Tk()
l = Label(root, text="hello" )
l.pack(padx=6, pady=4) # where padx and pady represent the x and y axis respectively
# well you can also use side=LEFT inside the pack method of the label widget.
Run Code Online (Sandbox Code Playgroud)
要基于列和行放置小部件,请使用网格方法:
but = Button(root, text="hello" )
but.grid(row=0, column=1)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
69800 次 |
| 最近记录: |