Version 1 of Strange behaviour with combobox and spinbox in procedures.

Updated 2017-11-19 22:38:19 by mue

Got a strange behaviour when passing variables from one procedure to another. I don't know, if this is a bug or a feature. Also I didn't made an extensive search in this forum, because I don't know how and what to search for ... Pardon me, I'm not a professional programmer. So maybe this is a bit offending to you cracks!

 package require Tk

 proc Toplevel {var} {
        toplevel .top
        set liste {3 2}

        pack [ttk::label .top.lb2 -text "$var"]

        # comment me off -- the spinbox!
        pack [spinbox .top.sb -values $liste -textvariable var]

        pack [ttk::combobox .top.cb1 -values $liste -textvariable var]

        pack [ttk::combobox .top.cb2 -values $liste -textvariable b]
        puts $var
 }

 proc mainwindow {} {
        set a 1
        set ::b 2
        pack [ttk::button .b -text "Push me" -command {Toplevel $::b}]
 }

 mainwindow

When I push the button of the main window, the lable in the toplevel windows tells the right value. Further more, the spinbox now tells the first value of the list (which is 3). Ok, strange, because textvariable var was sent from main window and should initiate the spinbox (in my opinion). Now var is set and the combobox tells the same. If you comment the spinbox off, the first combobox is left empty! Is it a bug? How to pass over a variable the right way?

Thanks a lot! PS. Sorry for my poor English, as I'm not a native speaker ...

<<bug?>>