tkinter:如何使这些框适合左侧并成直线

tkinter: How do I make these boxes fit to the left and be in straight line

如您所见,我的方框不是在一条直线上。我想让它们成一直线并且更靠左。 我的代码:

has_lower_box = tk.Checkbutton(root, text="lower chars", variable=has_lower_value)
has_lower_box.grid(row=0, column=1)
has_upper_box = tk.Checkbutton(root, text="upper chars", variable=has_upper_value)
has_upper_box.grid(row=1, column=1)
has_upper_box = tk.Checkbutton(root, text="special chars", variable=has_special_value)
has_upper_box.grid(row=2, column=1)

checkboxes

以下是如何使用 sticky= Tkinter Grid Geometry Manager 选项将它们排列起来。我把它设置为 sticky=W for West,这当然意味着左侧。

import tkinter as tk
from tkinter.constants import *

root = tk.Tk()

has_lower_value = tk.BooleanVar()
has_upper_value = tk.BooleanVar()
has_special_value = tk.BooleanVar()

has_lower_box = tk.Checkbutton(root, text="lower chars", variable=has_lower_value)
has_lower_box.grid(row=0, column=1, sticky=W)
has_upper_box = tk.Checkbutton(root, text="upper chars", variable=has_upper_value)
has_upper_box.grid(row=1, column=1, sticky=W)
has_upper_box = tk.Checkbutton(root, text="special chars", variable=has_special_value)
has_upper_box.grid(row=2, column=1, sticky=W)

root.mainloop()

这是显示结果的放大屏幕截图: