python - 关于网格的 Python tkinter 几何管理
问题描述
为了简单起见,我问一个简单的问题,
我想做 4 个按钮,每个(全填充)都停留在框架容器或 tkinter 窗口的一个角落:
button_1 = tkinter.Button(window, text="Button 1")
button_2 = tkinter.Button(window, text="Button 2")
button_3 = tkinter.Button(window, text="Button 3")
button_4 = tkinter.Button(window, text="Button 4")
button_1.grid(row=0, column=0)
button_2.grid(row=0, column=1)
button_3.grid(row=1, column=0)
button_4.grid(row=1, column=1)
但是,它们都是仅在窗口左上角保持在一起的小按钮,它们并没有像预期的那样填满整个窗口。
解决方案
btn.place
如果您不想使用网格系统,也可以使用基于坐标系放置按钮。请检查代码段
from tkinter import *
import tkinter as tk
window = Tk()
window.geometry('160x130')
button1 = Button(window, text="Button 1")
button1.place(x=0,y=0)
button2 = Button(window, text="Button 2")
button2.place(x=100,y=0)
button3 = Button(window, text="Button 3")
button3.place(x=0,y=100)
button4 = Button(window, text="Button 4")
button4.place(x=100,y=100)
window.mainloop()
推荐阅读
- reactjs - React js在按钮单击时获取表格数据
- java - 如何使用 Hibernate 处理 PostgreSQL XML 字段?
- elasticsearch - 重复数据 - Elasticsearch
- android - 天文台空对象参考
- excel - 数据透视表的内容格式
- html - Safari 中的 CSS 透视图/translateZ 问题
- javascript - 我已经使用 javascript 为移动设备创建了这个切换菜单,但这不起作用
- javascript - 测试字符串是否只包含字符
- linux - 取消作业时是否所有由 Slurm 作业启动的进程都被终止?
- javascript - 如何在 reactJS 中使用带有 momentJS 的 simple-react-validator 验证日期?