• Re: How to set ttk::radiobutton -variable to an object's instance? vari

    From Robert Heller@21:1/5 to Mark Summerfield on Fri Jul 11 10:09:44 2025
    At Fri, 11 Jul 2025 09:55:25 -0000 (UTC) Mark Summerfield <[email protected]> wrote:


    Given this class:

    oo::class create App {
    # ...
    variable ShowState
    }

    And this method:

    oo::define App method make_controls {} {
    # ...
    ttk::radiobutton .controlsFrame.showFrame.asIsRadio \
    -text "Show as-is" -value asis -variable ShowState
    set ShowState asis

    The variable given to the radio button and the instance variable
    are _different_.

    I tried these variations, all of which gave errors:

    -variable [my ShowState]
    -variable [my $ShowState]
    -variable [self ShowState]
    -variable [self $ShowState]

    For now I'm using a global variable ::ShowState
    but I'd really like it to be an instance variable -
    if it can be done?


    I don't know anything about how Tcl OO system works, but with SNIT I can do this:

    package require snit
    package require Tk

    snit::widget foo {
    variable ShowState

    constructor {args} {
    # ...
    ttk::radiobutton $win.controlsFrame.showFrame.asIsRadio \
    -text "Show as-is" -value asis -variable [myvar ShowState]
    # ...
    }
    }



    --
    Robert Heller -- Cell: 413-658-7953 GV: 978-633-5364
    Deepwoods Software -- Custom Software Services
    http://www.deepsoft.com/ -- Linux Administration Services
    [email protected] -- Webhosting Services

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)