Skip to content

Default values in tkinter stubs #10947

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Akuli opened this issue Oct 29, 2023 · 0 comments
Open

Default values in tkinter stubs #10947

Akuli opened this issue Oct 29, 2023 · 0 comments
Labels
help wanted An actionable problem of low to medium complexity where a PR would be very welcome topic: tkinter tkinter-related issues

Comments

@Akuli
Copy link
Collaborator

Akuli commented Oct 29, 2023

Tkinter is very dynamic. Most keyword arguments are passed to Tcl, and their behavior is described best in manual pages written for Tcl users. This means that when we ran stubdefaulter to figure out default values for most functions in typeshed, it didn't do much for tkinter, and most of tkinter's default values are still = ....

I (or someone else) should go through the = ... occurrences and fill in whatever can be filled. Often the default values are platform-specific, and hard-coding something into the stubs doesn't make sense.

Most defaults in tkinter are widget options (__init__ and configure() methods). To see their default values on your system, you can instantiate the widget and convert it to a dict. For example:

>>> import pprint
>>> import tkinter
>>> pprint.pprint(dict(tkinter.Text()))
{'autoseparators': 1,
 'background': '#3b3b3e',
 'bd': 1,
 'bg': '#3b3b3e',
 'blockcursor': 0,
 'borderwidth': 1,
 'cursor': 'xterm',
 'endline': '',
 'exportselection': 1,
 'fg': '#ffffff',
 'font': 'TkFixedFont',
 'foreground': '#ffffff',
 'height': 24,
 'highlightbackground': '#3b3b3e',
 'highlightcolor': '#ffffff',
 'highlightthickness': 1,
 'inactiveselectbackground': '#c3c3c3',
 'insertbackground': '#000000',
 'insertborderwidth': 0,
 'insertofftime': 300,
 'insertontime': 600,
 'insertunfocussed': 'none',
 'insertwidth': 2,
 'maxundo': 0,
 'padx': 1,
 'pady': 1,
 'relief': 'sunken',
 'selectbackground': '#7d7d82',
 'selectborderwidth': <pixel object: '0'>,
 'selectforeground': '#ffffff',
 'setgrid': 0,
 'spacing1': 0,
 'spacing2': 0,
 'spacing3': 0,
 'startline': '',
 'state': 'normal',
 'tabs': '',
 'tabstyle': 'tabular',
 'takefocus': '',
 'undo': 0,
 'width': 80,
 'wrap': 'char',
 'xscrollcommand': '',
 'yscrollcommand': ''}
@Akuli Akuli added the topic: tkinter tkinter-related issues label Oct 29, 2023
@AlexWaygood AlexWaygood added the help wanted An actionable problem of low to medium complexity where a PR would be very welcome label Nov 1, 2023
Akuli pushed a commit that referenced this issue Feb 10, 2024
Add defaults for `tkinter`'s `__init__` methods, see #10947 

Some notes about specific arguments:
- `variable` and `textvariable`: The default value (using `dict`) is consistently `""` but this doesn't match the annotated `Variable` type so I didn't fill these in
- `Message(padx, pady)`: The default value is `-1` which is not allowed according to the documentation so I didn't fill this in
- `Toplevel(use)`: The default value is always `""` but this doesn't match the annotated `int` type so I didn't fill this in
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted An actionable problem of low to medium complexity where a PR would be very welcome topic: tkinter tkinter-related issues
Projects
None yet
Development

No branches or pull requests

2 participants