Python 关于网格的 tkinter 几何管理
Python tkinter geometry management about grid
为了简单起见,我问一个简单的问题,
我想制作 4 个按钮,每个按钮(全填充)位于框架容器或 tkinter 的一个角 window:
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)
然而,它们都是小按钮,仅在 window 的左上角聚集在一起,并没有像预期的那样填满整个 window。
如果不想使用网格,也可以使用 btn.place
根据坐标系放置按钮 system.Please 检查代码段
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()
为了简单起见,我问一个简单的问题,
我想制作 4 个按钮,每个按钮(全填充)位于框架容器或 tkinter 的一个角 window:
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)
然而,它们都是小按钮,仅在 window 的左上角聚集在一起,并没有像预期的那样填满整个 window。
如果不想使用网格,也可以使用 btn.place
根据坐标系放置按钮 system.Please 检查代码段
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()