Skip to content

Added list and tuple to grid sticky option.#15508

Open
melassa wants to merge 5 commits intopython:mainfrom
melassa:master
Open

Added list and tuple to grid sticky option.#15508
melassa wants to merge 5 commits intopython:mainfrom
melassa:master

Conversation

@melassa
Copy link
Contributor

@melassa melassa commented Mar 13, 2026

Added list and tuple to grid sticky option.

@Akuli
Copy link
Collaborator

Akuli commented Mar 13, 2026

This is not the only place where sticky is defined. Searching for sticky gives me:

$ git grep -n sticky
tkinter/__init__.pyi:1141:    sticky: str  # consists of letters 'n', 's', 'w', 'e', no repeats, may be empty
tkinter/__init__.pyi:1156:        sticky: str = ...,  # consists of letters 'n', 's', 'w', 'e', may contain repeats, may be empty
tkinter/ttk.pyi:62:    sticky: str  # consists of letters 'n', 's', 'w', 'e', may contain repeats, may be empty
tkinter/ttk.pyi:75:    sticky: str
tkinter/ttk.pyi:149:        sticky: str = ...,
tkinter/ttk.pyi:697:        sticky: str = ...,  # consists of letters 'n', 's', 'w', 'e', no repeats, may be empty

If you need help figuring out which sticky's should be str and which should be str | list[str] | tuple[str, ...], just let me know :)

@github-actions

This comment has been minimized.

@Akuli
Copy link
Collaborator

Akuli commented Mar 13, 2026

For example, _GridInfo should be just str:

>>> label.grid(sticky=tuple('nswe'))
>>> label.grid_info()['sticky']
'nesw'
>>> label.grid(sticky=list('nswe'))
>>> label.grid_info()['sticky']
'nesw'

@melassa
Copy link
Contributor Author

melassa commented Mar 13, 2026

Notebook add() requires it. Layout do not accept list or tuple.

@melassa
Copy link
Contributor Author

melassa commented Mar 13, 2026

I must open a new PR for Notebook?

@melassa
Copy link
Contributor Author

melassa commented Mar 13, 2026

All done, for me.

@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

*,
state: Literal["normal", "disabled", "hidden"] = ...,
sticky: str = ..., # consists of letters 'n', 's', 'w', 'e', no repeats, may be empty
sticky: str | list[str] | tuple[str, ...] = ..., # consists of letters 'n', 's', 'w', 'e', no repeats, may be empty
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work on my system:

>>> from tkinter import ttk
>>> nb = ttk.Notebook()
>>> label = ttk.Label(nb)
>>> nb.add(label, sticky=list('nswe'))
Traceback (most recent call last):
  File "<python-input-3>", line 1, in <module>
    nb.add(label, sticky=list('nswe'))
    ~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/tkinter/ttk.py", line 824, in add
    self.tk.call(self._w, "add", child, *(_format_optdict(kw)))
    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_tkinter.TclError: Bad -sticky specification n s w e

Maybe this has to do with Tk version? What's yours?

>>> import tkinter
>>> tkinter.TkVersion
8.6

Copy link
Contributor Author

@melassa melassa Mar 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. Do not work. I made a mistake when testing it. Seems that grid is the only one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants