在 Tkinter 中,widget.rowconfigure 或 widget.grid_rowconfigure 哪一个才是正确的?
使用 Tkinter 构建应用程序时,我们可以使用许多组件和小部件来扩展该应用程序。为了在应用程序中渲染这些小部件,我们使用几何管理器。
几何管理器负责配置小部件在窗口中的位置和大小。网格几何管理器按行和列处理要放置的小部件。
如果要让小部件跨越一个或多列,我们使用 widget.rowconfigure() 或 widget.grid_rowconfigure()。它采用 权重和 行/列值等参数。
widget.rowconfigure() 有时用在 widget.grid_rowconfigure() 的位置。使用这些方法将允许小部件具有可以在行和列中应用的权重属性。
示例
# Import the required libraries
from tkinter import *
# Create an instance of tkinter frame or window
win=Tk()
# Set the size of the window
win.geometry("700x350")
# Add a new Frame
f1=Frame(win, background="bisque", width=10, height=100)
f2=Frame(win, background="blue", width=10, height=100)
# Add weight property to span the widget in remaining space
f1.grid(row=0, column=0, sticky="nsew")
f2.grid(row=0, column=1, sticky="nsew")
win.columnconfigure(0, weight=1)
win.rowconfigure(1, weight=0)
win.mainloop()输出
运行上述代码将在窗口中显示一些彩带。这些彩带可以赋予权重属性,以便在给定中提供额外的空间。
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP