python - tkinter:如何使这些框适合左侧并成直线
问题描述
如您所见,我的盒子不在一条直线上。我想让它们在直线上,更靠左。我的代码:
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)
解决方案
sticky=
以下是如何使用Tkinter Grid Geometry Manager选项将它们排列起来。我将它设置sticky=W
为 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()
这是显示结果的放大屏幕截图:
推荐阅读
- express - 护照JS如何处理会话cookie?
- c - 使用 getopt() - 打开、读取和写入文件
- office365 - 在 RDP 上安装团队
- string - 如何将字符串的第二个和第三个字符作为整数 - C89
- r - 具有比例和因子数据的 geom_histogram
- django - Django Bad Reqsut 400 问题
- python-3.x - PyMuPDF 如何删除注释?
- kubernetes - 云平台如何保证服务不宕机
- bash - `inotifywait` 不会在带有 `-e delete_self` 的 bash 脚本中终止;但在交互式外壳中
- django - 如何使用 MySQL 数据库在 Django 中为非洲/卢萨卡设置时区