get id widget tkinter 1

get id widget tkinter

You can override the auto-generated name by giving a name when you create a widget, using the 
name parameter. You can then use str to get the name.

For example:

>>> import Tkinter as tk
>>> root = tk.Tk()
>>> f = tk.Frame(root, name="foo")
>>> b1 = tk.Button(f, name="b1")
>>> str(b1)
>>> root.nametowidget(".foo.b1")

>>> b1

Here is what the above code is Doing:
1. Import the Tkinter module.
2. Create a root window.
3. Create a frame widget.
4. Create a button widget.
5. Get the name of the button widget.
6. Get the widget with the name “.foo.b1”.
7. Get the widget with the name “b1”.

Similar Posts