Version 0 of tk_optionMenu with a long list

Updated 2013-12-14 00:37:48 by Zipguy

tk_optionMenu with a long list, has scrolling

Zipguy 2013-12-12 - You can find out my email address by clicking on Zipguy.

I think that tk_optionMenu is a great command. It does give you choices, will default to, whatever you choose, will set your variable, and show that, on the button. Slick.

Even better, if you have too many options to fit on the screen, it will fit them, and it has scrolling built-in, to that command.

I made a simple program which uses a list. It is a list of animals, unsorted. Here's what it looks like:

http://www.geocities.ws/thezipguy/tcl/misc/tkom_01.png

So, if you click on the button labelled 'Pick an Animal (unsorted)' (which is highlighted in red), you will see a screen like this:

http://www.geocities.ws/thezipguy/tcl/misc/tkom_02.png

Note that, without moving the mouse, it has filled the screen, with options, to choose. But, if you look closely, you will notice an arrow, pointing down, at the bottom of the screen:

http://www.geocities.ws/thezipguy/tcl/misc/tkom_03.png

On the screen above it is highlighted in red. If you click on that button, the screen will scroll down. If you do so, you will see a screen like this:

http://www.geocities.ws/thezipguy/tcl/misc/tkom_04.png

Once you've made a selection (I've selected 'Lepoard'), you will see a screen like this:

http://www.geocities.ws/thezipguy/tcl/misc/tkom_05.png

All that means, is that you have selected 'Lepoard', and that's the name of the animal, that shows on the button. The self-same button used to show 'Pick an Animal (unsorted)'.

Code

Here's the code that created thoose screens:

====

        # Written by zipguy on 2013-12/12
        # Shows you the joys of tk_optionMenu with a long list
        #
        set alist                                                         [list {Tarantula} {Aardwolf} {African bush elephant} {Amazon river dolphin} {American alligator} {Aardvark} {Tasmanian devil} {Green anaconda} {Tiger} {Tiger shark} {American white pelican} {Andean condor} {Turkey} {Arabian camel} {Asian elephant} {Atlantic salmon} {Bahaman raccoon} {Bald eagle} {Banded pitviper} {Black wildebeest} {Blue whale} {BobcatCapybara} {Caribou (reindeer)} {Cheetah} {Common bottlenose dolphin} {Common chimpanzee} {Cougar} {Coyote} {Dingo Eastern diamondback rattlesnake} {Elephant seal} {Elk} {Emperor penguin Emu} {European otter} {Four-horned antelope} {Giant anteater} {Giant panda} {Iguana} {Impala} {Snow leopard} {Snowy owl} {Giraffe} {Golden hamster} {Golden-capped fruit bat} {Gray fox} {Wolf} {Great spotted kiwi} {California condor} {California sea lion} {Great white shark} {Greater dwarf lemur} {Gray heron} {Gray squirrel} {Guinea baboon} {Guinea pig} {Hedgehog} {Hippopotamus} {Horse} {Sparrow} {Sperm whale} {Spider monkey} {Spotted halibut} {Jackal} {Jaguar} {Kangaroo rat} {Killer whale} {King cobra} {Koala bear} {Komodo dragon} {Leatherback turtle} {Leopard} {Lion} {Marsh rabbit} {Mekong giant catfish} {Nightingale} {Nine-banded armadillo} {North American beaver} {Northern cardinal} {Northern flying squirrel} {Ocelot} {Orangutan} {Ostrich} {Peregrine falcon} {Bee hummingbird} {Black rhinoceros} {Black widow spider} {Polar bear} {Praying mantis} {Red kangaroo} {Red panda} {Spotted hyena} {Spur-thighed tortoise} {Virginia opossum} {Western gorilla} {White-backed vulture} {American bison} {American crow} {American flamingo} {Wildcat} {Wolverine}]

        wm title . "tk_optionMenu with a long list"
        wm minsize . 300 60

        tk_optionMenu .foo1 myVar1 "Pick an Animal (unsorted)"
        pack .foo1
        foreach x $alist { 
                .foo1.menu add radiobutton -label $x -variable myVar1 \
                        -command "puts \"Current choice1=<$x>\""
        }

        tk_optionMenu .foo2 myVar2 "Pick an Animal   (sorted)"
        pack .foo2
        foreach x [lsort -dictionary $alist] { 
                .foo2.menu add radiobutton -label $x -variable myVar2 \
                        -command "puts \"Current choice2=<$x>\""
        }

====