saiftynet has asked for the wisdom of the Perl Monks concerning the following question:
I am learning Perl and GUI development, and working currently on code that will work on multiple toolkits (Tk, Wx, Gtk etc). I need help with Tk. For my purposes I have to place all my widgets (rather than pack->() them). I wish to create a fixed sized, fixed position scrolling Listbox, to be later populated by other items. This works perfectly well if I insert strings, I appear not to be able to insert other widgets (e.g Checkbuttons).
Have searched many places, and most suggest I should use pack->(), but I guess mixing pack and place does not work, and I am committed to use pack for my use-case. Your guidance will be gratefully received,#!/usr/bin/perl use strict; use Tk; my $mw = MainWindow->new; $mw->geometry('400x250'); my $canvas = $mw->Canvas( -bg => 'lavender', -relief => 'sunken', -width => 400, -height => 250)->pack(-expand => 1, -fill => 'both'); my $size=[200,200]; # size of the widget my $location=[50,12]; # position of widget my @strings2 = qw/apples bananas pears grapes/ x 5; $canvas->{"listbox"}=$mw->Scrolled("Listbox", -bg => 'white', -scrollbars => "e", -selectmode => 'extended', -width => (${$size}[0])/7, # some scaling -height => (${$size}[1]+12)/15); # scaling $canvas->{"listbox"}->insert('end',@strings2); # This works $canvas->createWindow(${$location}[0] ,${$location}[1], -anchor => "nw", -window => $canvas->{"listbox"}); MainLoop();
saif
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: TK Placing Widgets in a Scrolling Pane
by kcott (Archbishop) on Dec 03, 2021 at 17:12 UTC | |
by saiftynet (Initiate) on Dec 03, 2021 at 19:56 UTC | |
by Marshall (Canon) on Dec 04, 2021 at 01:19 UTC | |
by kcott (Archbishop) on Dec 04, 2021 at 07:43 UTC | |
by Anonymous Monk on Dec 04, 2021 at 20:15 UTC | |
by kcott (Archbishop) on Dec 05, 2021 at 09:35 UTC | |
|
Re: TK Placing Widgets in a Scrolling Pane
by tybalt89 (Monsignor) on Dec 03, 2021 at 21:29 UTC | |
|
Re: TK Placing Widgets in a Scrolling Pane
by Anonymous Monk on Dec 03, 2021 at 18:09 UTC | |
|
Re: TK Placing Widgets in a Scrolling Pane
by Anonymous Monk on Dec 03, 2021 at 18:23 UTC | |
by Anonymous Monk on Dec 03, 2021 at 21:10 UTC |