Skip to content

Commit 4e37a4b

Browse files
committed
StringVar
1 parent 57b212b commit 4e37a4b

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

gui-programming.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,19 @@ for item in ["Laudrup", "McCoist", "Albertz", "Ferguson"]:
7979
# insert the item at the END of the listbox
8080
hof_gers.insert(tk.END, item)
8181
```
82-
* `Canvas` - a widget that can be used to draw shapes, images, and text. Tkinter does not support 3D graphics. For complex 3D graphics, libraries such as [PyOpenGL](https://pyopengl.sourceforge.net/) and [Visualisation Toolkit (VTK)](https://pypi.org/project/vtk/) would be more suitable.
82+
* `Canvas` - a widget that can be used to draw shapes, images, and text. Tkinter does not support 3D graphics. For complex 3D graphics, libraries such as [PyOpenGL](https://pyopengl.sourceforge.net/) and [Visualisation Toolkit (VTK)](https://pypi.org/project/vtk/) would be more suitable.
83+
84+
`StringVar` - a special variable that can be used to store a string value. It is used to store the value of a widget, such as an `Entry` or a `Label`. It can be used to get and set the value of a widget.
85+
86+
:information_source: You need to associate a `StringVar` with a widget to make it work. For example, you can associate a `StringVar` with an `Entry` widget to get the value of the entry field, or at the very least the master widget (e.g. the `Tk()` root window)
87+
88+
For example, this would throw an error because the `StringVar` is not associated with any widget:
89+
```python
90+
import tkinter as tk
91+
92+
rrp = tk.StringVar()
93+
rrp.set("I have come here to chew bubble gum and kick ass, and I'm all out of bubble gum")
94+
95+
window = tk.Tk()
96+
window.mainloop()
97+
```

0 commit comments

Comments
 (0)