How does `tkinter. Spinbox()` behaviour depends on the type of value passed to its `textvariable`
Question: Been trying to pick up on Python (3.4) and this is my first posting on Stack
Overflow. I have questions regarding the behaviour of the `textvariable`
option in the `tkinter.Spinbox()` widget constructor.

The following codes are working. It's a layout of 6 spinboxes, there are 3
pairs of spinboxes (each pair side by side). Each spinbox in a pair are
suppose to be independent of each other, i.e. when one changes, it's not
suppose to affect the other.

Pair A receives their `textvariable` parameter as type `StringVar()` (e.g.
`var = StringVar()`)

Pair B receives their `textvariable` parameter as string declared between
quotes (e.g. `var = '0'`)

Pair C receives their `textvariable` parameter as type `integer` (e.g. `var =
0`)

Note: I'd like to post a screen capture of the resulting window but the page
said "You need at least 10 reputation to post images"... of which I apparently
do not have at the moment...

I'd just like to understand what is the reason behind why the members of Pair
C seems to be "non-independent" of each other? -> Change one, and the other
follows the with the same changes made.

How is the intepretation for the `textvariable` parameter in the
`tkinter.Spinbox()` different for different types of value assigned?

Here are my codes:

    
    
    from tkinter import *
    
    class spinModuleStrA():
        ''' spinModuleNum() - Spinbox taking textvariable as <StringVar() value> '''
        def __init__(self, master, moduleName):
            self.root = master
            self.moduleName = moduleName
            self.root.grid()
            self.var = StringVar()
            self.var.set('r')
    
            self.label1 = Label(self.root, text=self.moduleName, bg=self.root["bg"])
            self.label1.pack(expand = True)
    
            self.spinBox1 = Spinbox(self.root ,from_=0, to=100, width=10, textvariable=self.var)
            self.spinBox1.pack(expand = True)
    
    
    class spinModuleStrB():
        ''' spinModuleNum() - Spinbox taking textvariable as <'' string value> '''
        def __init__(self, master, moduleName):
            self.root = master
            self.moduleName = moduleName
            self.root.grid()
            self.var = ''
    
            self.label1 = Label(self.root, text=self.moduleName, bg=self.root["bg"])
            self.label1.pack(expand = True)
    
            self.spinBox1 = Spinbox(self.root ,from_=0, to=100, width=10, textvariable=self.var)
            self.spinBox1.pack(expand = True)
    
    
    class spinModuleNum():
        ''' spinModuleNum() - Spinbox taking textvariable as <numerical value> '''
        def __init__(self, master, moduleName):
            self.root = master
            self.moduleName = moduleName
            self.root.grid()
            self.var = 0
    
            self.label1 = Label(self.root, text=self.moduleName, bg=self.root["bg"])
            self.label1.pack(expand = True)
    
            self.spinBox1 = Spinbox(self.root ,from_=0, to=100, width=10, textvariable=self.var)
            self.spinBox1.pack(expand = True)
    
    
    class app():
        def __init__(self):
            self.root = Tk()
            self.root.geometry('300x300+500+200')
            for i in range(2): # number of columns
                self.root.columnconfigure(i, weight=1)
    
            for i in range(3): # number of rows
                self.root.rowconfigure(i, weight=1)
    
            self.frame1 = Frame(self.root, bg='#f55')
            self.frame1.grid(row=0, column=0, padx=10, pady=10, sticky=W+E+N+S)
            self.module1 = spinModuleStrA(self.frame1, "Spin <StringVar()> A")
    
            self.frame2 = Frame(self.root, bg='#faa')
            self.frame2.grid(row=0, column=1, padx=10, pady=10, sticky=W+E+N+S)
            self.module2 = spinModuleStrA(self.frame2, "Spin <StringVar() B>")
    
            self.frame3 = Frame(self.root, bg='#5f5')
            self.frame3.grid(row=1, column=0, padx=10, pady=10, sticky=W+E+N+S)
            self.module3 = spinModuleStrB(self.frame3, "Spin <''> A")
    
            self.frame4 = Frame(self.root, bg='#5fa')
            self.frame4.grid(row=1, column=1, padx=10, pady=10, sticky=W+E+N+S)
            self.module4 = spinModuleStrB(self.frame4, "Spin <''> B")
    
            self.frame5 = Frame(self.root, bg='#55f')
            self.frame5.grid(row=2, column=0, padx=10, pady=10, sticky=W+E+N+S)
            self.module5 = spinModuleNum(self.frame5, "Spin <numerical> A")
    
    
            self.frame6 = Frame(self.root, bg='#5af')
            self.frame6.grid(row=2, column=1, padx=10, pady=10, sticky=W+E+N+S)
            self.module6 = spinModuleNum(self.frame6, "Spin <numerical> B")
    
    app1 = app()
    


Answer: The reason is irrelevant. Passing a string or integer to the textvariable
option is incorrect usage. While it will sometimes work (depending on how you
define "work"), it is incorrect. The textvariable requires one of the special
variable classes provided by tkinter. Without using one of those, there's no
point in defining the textvariable attribute at all.

However, to answer the specific question:

**Pair A** each get a unique textvariable, so it works as expected. The
underlying tcl/tk engine gets a unique string for each instance, which is why
the two are independent.

**Pair B** effectively gets _no_ textvariable because you specify the empty
string. To the underlying tcl/tk engine an empty string in this situation is
equivalent to python's `None`. If, instead of `''` you had used a non-empty
string (eg: `'w00t'`), you would notice the same behavior as pair C. This is
because each spinbox gets a variable with the same name, which to the
underlying tcl/tk engine means they are the same textvariable and thus tied
together.

**Pair C** uses a constant 0 (zero). Because it is a constant, both widgets
effectively get the same textvariable because ultimately this parameter
becomes the name of an tcl/tk variable. Since the name is identical for both
spinboxes, they are tied together.

