O'Reilly logo

Python GUI Programming Cookbook by Burkhard A. Meier

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to use StringVar()

There are built-in programming types in tkinter that differ slightly from the Python types we are used to programming with. StringVar() is one of those tkinter types.

This recipe will show you how to use the StringVar() type.

Getting ready

We are learning how to save data from the tkinter GUI into variables so we can use that data. We can set and get their values, very similar to the Java getter/setter methods.

Here are some of the available types of coding in tkinter:

strVar = StringVar()

# Holds a string; the default value is an empty string ""

intVar = IntVar()

# Holds an integer; the default value is 0

dbVar = DoubleVar()

# Holds a float; the default value is 0.0

blVar = BooleanVar()

# Holds a Boolean, it ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required