【问题标题】:Python tkinter geometry management about grid关于网格的 Python tkinter 几何管理
【发布时间】:2020-09-06 06:04:11
【问题描述】:

为了简单起见,我问一个简单的问题,

我想做 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)

但是,它们都是小按钮,只在窗口的左上角在一起,并没有像预期的那样填满整个窗口。

【问题讨论】:

标签: python tkinter geometry grid


【解决方案1】:

如果您不想使用网格系统,也可以使用btn.place基于坐标系放置按钮。请检查sn-p

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() 

【讨论】:

  • Place and resize 似乎可以完成这项工作,但我渴望的是您的 grid_columnconfigure 和 grid_rowconfigure,谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-06-10
  • 2019-05-05
  • 1970-01-01
  • 2013-05-03
  • 2021-01-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多