Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is correct: widget.rowconfigure or widget.grid_rowconfigure?

When using grid geometry manager. Let's say you have:

import tkinter as tk
from tkinter import ttk

root = tk.Tk()
root.rowconfigure(0, weight=1)
root.columnconfigure(0, weight=1)
ttk.Button(root, text="Hello World").grid(sticky=tk.NSEW)
root.mainloop()

The part where you specify the weight of the row/column can also be coded up as:

root.grid_rowconfigure(0, weight=1)
root.grid_columnconfigure(0, weight=1)

For this example, what is correct method: widget.rowconfigure or widget.grid_rowconfigure? and why?

Bonus: From an implementation POV, why do both work?

like image 350
Trevor Boyd Smith Avatar asked Aug 16 '13 19:08

Trevor Boyd Smith


People also ask

What is Grid_rowconfigure?

grid_rowconfigure(). It takes params such as weight and row/col value. The widget. rowconfigure() is sometimes used in place of widget.

What is Ipadx and Ipady in Tkinter?

ipadx, ipady − How many pixels to pad widget, horizontally and vertically, inside widget's borders. padx, pady − How many pixels to pad widget, horizontally and vertically, outside v's borders. row − The row to put widget in; default the first row that is still empty.

What does sticky Nsew mean?

If you want the widget to expand to fill up the entire cell, grid it with a sticky value of nsew (north, south, east, west), meaning it will stick to every side. This is shown in the bottom left widget in the above figure. Most widgets have options that can control how they are displayed if they are larger than needed.

Can I use grid and pack together?

Important: pack(), place(), and grid() should not be combined in the same master window. Instead choose one and stick with it.


1 Answers

widget.rowconfigure is literally just an alias for widget.grid_rowconfigure. In the source code for tkinter is this line of code:

rowconfigure = grid_rowconfigure

I don't know for a fact, but I suspect that widget.rowconfigure was just added for convenience. Frankly, I didn't even know it existed until I read this question.

In my opinion, grid_rowconfigure is the proper name to use. I say that because tkinter is an interface to an underlying tcl/tk interpreter, and in tcl/tk the command is grid rowconfigure. Since most tkinter functions mirror the naming conventions of the tcl/tk functions as close as possible, grid_rowconfigure is the natural choice.

like image 140
Bryan Oakley Avatar answered Sep 20 '22 02:09

Bryan Oakley