Skip to content

bpo-13553: Document tkinter.Tk args #4786

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

Merged
merged 8 commits into from
May 10, 2022
Merged

Conversation

csabella
Copy link
Contributor

@csabella csabella commented Dec 11, 2017

@terryjreedy
Copy link
Member

terryjreedy commented Dec 12, 2017

None of my comments are outdated by applying Serhiy's suggestions. My review just happened to start before the patch arrived, and except for 1, happen to be attached to the same sentences. Serhiy, please also review my comments.

Specifies that the main window for the application is to be embedded in
the window whose identifier is given, instead of being created as an
independent toplevel window.

Copy link
Member

Choose a reason for hiding this comment

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

While we are documenting the Tk class. Would it be worth it to document Tk attributes? master, children and tk.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The current page reads more like a 'getting started' or 'how to', so I wasn't sure how much detail to add. I know there's a separate bug issue where Terry figured out the difference between master and parent, so maybe it would be worthwhile to include that here?

@csabella
Copy link
Contributor Author

I have made the requested changes; please review again.

@csabella
Copy link
Contributor Author

@terryjreedy @serhiy-storchaka @vstinner
I've made additional changes to document the attributes and to remove the documentation of readprofile. Thanks!

terryjreedy
terryjreedy previously approved these changes Feb 2, 2018
@terryjreedy terryjreedy closed this Feb 2, 2018
@terryjreedy terryjreedy reopened this Feb 2, 2018
@terryjreedy terryjreedy dismissed their stale review February 2, 2018 22:09

I don't know the function well enough to approve, as oppose to disapprove.

@ned-deily
Copy link
Member

@csabella Sorry this has languished. Currently, there is some extensive tkinter documentation review going on in some other PRs. Perhaps @roseman would be willing to review your proposed changes once the other changes are settled on.

program name (``sys.argv[0]``).
*className*
Name of the widget class. Used as a profile file and also as the name
with which Tcl is invoked (*argv0* in *interp*).
Copy link
Contributor

Choose a reason for hiding this comment

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

So about baseName and className...

My understanding is that className is the equivalent of wish's "-name" option. So this provides the default title for the root window, the class of the root window (which can be used in bindings and option database), and would be what is returned by "tk appname" (sometimes used for inter-application communication).

It appears that baseName isn't passed into Tcl/Tk at all.

About those profile files that can be read in... does anyone know what they're intended to be used for, if they've ever been documented, and if they're actually used at all? It reads like a per-application 'automatically inject your own code' which seems a bit strange.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried out specifying className on a call and it seems to lower case the first letter:

root = tkinter.Tk(className='TEST')

creates a window with the name tEST and root.tk.call('tk', 'appname') returns tEST. Should I document that behavior? Since fileName in the wish documentation is used to find the script, I think it might be lowercased for that reason?

Looking through the documentation, it looks like interp is used for inter-application communication, which is the value stored in Tk.tk.

tk appname ?newName?
    If newName is not specified, this command returns the name of the application (the name
    that may be used in **send** commands to communicate with the application)

However, the send command in tkinter has:

    def send(self, interp, cmd, *args):
        """Send Tcl command CMD to different interpreter INTERP to be executed."""
        return self.tk.call(('send', interp, cmd) + args)

As far as the profile files, there was a security patch in the past.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure why the first letter is lowercased - it's Tkinter that's doing it, though for what reason I can't guess. From the Tcl side it's perfectly ok with the first letter of argv0 capitalized. My instinct therefore is not to document it.

Note that the classname for the window will lowercase everything except for uppercasing the first letter, e.g. "Test" with your example. I think the first letter uppercase is used for user class names vs. builtin ones like 'button' etc. I was playing around with different things using this:

r = Tk(className='TEST')
print(r.call('tk','appname'))
print(r.wm_title())
print(r.bindtags())
print(sys.argv[0])

I'd suggest not documenting this conversion either. Anyone who needs to get the exact capitalization of the classname will know how to get it through introspection. I also don't imagine that 'send' would be used much by Tkinter apps (it was a useful thing a long while ago, not so much now).

Any suggestions how to proceed with regard to the readprofile() thing, i.e. what on earth it is for and if it should still be there? @serhiy-storchaka ?

are reported immediately.
*use*
Specifies the *id* of the main window in which to embed the application,
instead of it being created as an independent toplevel window. *id* must
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be "Specifies the id of the window". This whole piece was used for application embedding (think web browser plugins). Therefore, it would be almost always the case that you'd embed inside a specific subwindow somewhere, not directly in the "main" window of the application (which I'd read as toplevel)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you. I think I had taken this from the wish man page and unintentionally changed the meaning slightly with my edit.

@csabella
Copy link
Contributor Author

csabella commented Jun 5, 2018

Thank you @roseman for the review! I've pushed some of the changes, but still needed some clarification on the className as far as the uses and the behavior that should be documented.

@roseman
Copy link
Contributor

roseman commented Jun 6, 2018

I think for className, saying it sets the window's class, which can be used when specifying event bindings (see documentation for 'bindtags').

The profile thing I just don't know about..

@serhiy-storchaka serhiy-storchaka added the docs Documentation in the Doc dir label Dec 8, 2018
@vstinner
Copy link
Member

I removed the " needs backport to 3.6" label, the 3.6 branch no longer accept bugfixes (only security fixes are accepted): https://devguide.python.org/#status-of-python-branches

@JulienPalard
Copy link
Member

@csabella Looks like this PR is almost OK, maybe just missing the mention that className permits to choose the title of the window (last message of Mark). I tried to mark as resolved every actually resolved comments, I'll let you read the rest of them a last time.

Copy link
Member

@JelleZijlstra JelleZijlstra left a comment

Choose a reason for hiding this comment

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

Looks good, it seems the remaining comments don't need to be blocking.

@JelleZijlstra JelleZijlstra self-assigned this May 8, 2022
@JelleZijlstra JelleZijlstra added needs backport to 3.9 only security fixes needs backport to 3.10 only security fixes needs backport to 3.11 only security fixes labels May 8, 2022
@JelleZijlstra
Copy link
Member

Planning to merge this unless someone has further comments.

@taleinat
Copy link
Contributor

taleinat commented May 9, 2022

LGTM

@JelleZijlstra JelleZijlstra merged commit c56e2bb into python:main May 10, 2022
@miss-islington
Copy link
Contributor

Thanks @csabella for the PR, and @JelleZijlstra for merging it 🌮🎉.. I'm working now to backport this PR to: 3.9, 3.10, 3.11.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 10, 2022
(cherry picked from commit c56e2bb)

Co-authored-by: Cheryl Sabella <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 10, 2022
(cherry picked from commit c56e2bb)

Co-authored-by: Cheryl Sabella <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 10, 2022
(cherry picked from commit c56e2bb)

Co-authored-by: Cheryl Sabella <[email protected]>
miss-islington added a commit that referenced this pull request May 10, 2022
(cherry picked from commit c56e2bb)

Co-authored-by: Cheryl Sabella <[email protected]>
miss-islington added a commit that referenced this pull request May 10, 2022
(cherry picked from commit c56e2bb)

Co-authored-by: Cheryl Sabella <[email protected]>
miss-islington added a commit that referenced this pull request May 10, 2022
(cherry picked from commit c56e2bb)

Co-authored-by: Cheryl Sabella <[email protected]>
hello-adam pushed a commit to hello-adam/cpython that referenced this pull request Jun 2, 2022
(cherry picked from commit c56e2bb)

Co-authored-by: Cheryl Sabella <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.