Re: how to set focus

On Aug 14, 2009, at 10:06 AM, Sreejith S wrote:


Im using Gtk2-Perl..Can i able to set the focus to different widgets according to the keys (like keyascii).??

Using the Tab key to cycle through focusable widgets works out of the box. You can mangle the order if you need, but you shouldn't need to.

If you want to be able to hit alt+a to jump to the Address: input, then you want mnemonic labels:

Note that Gtk2::Label::new() is actually an alias for new_with_mnemonic, so the flow would look like this:

   $name_label = Gtk2::Label->new ("_Name:");
   $name_entry = Gtk2::Entry->new ();
   $name_label->set_mnemonic_for ($name_entry);

   $address_label = Gtk2::Label->new ("_Address:");
   $address_entry = Gtk2::Entry->new ();
   $address_label->set_mnemonic_for ($address_entry);

   # and then pack and show those...

In your window, hitting alt+n will put the cursor in the Name entry, and alt+a will put the cursor in the Address entry -- and it will select the current contents, since the user likely wants to replace it.

I also need to clear the contents of all the widgets which are placed in a vbox,when i pressed a clear that posiible??

You'll have to keep a list of the entries you want to clear:

    foreach my $e (@{ $mybox->{entries} }) {
        $e->set_text ('');

Santa ate all the cookies!
  -- Zella's first, indignant words on Christmas morning, '07.

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]