Sponsored Content
Full Discussion: Perl/Tk - user value
Top Forums Shell Programming and Scripting Perl/Tk - user value Post 302555198 by vasanth.vadalur on Wednesday 14th of September 2011 06:25:30 AM
Old 09-14-2011
Question Perl/Tk - user value

Hi,

I am new to perl TK world.

I am having doubt that for the below code.

How to take the value of selected and text box value from out of the loop.




Code:
#!/usr/bin/perl
use strict;
use Tk;
use Tk::BrowseEntry;
my $mw = MainWindow->new;

# Mainwindow: sizex/y, positionx/y
$mw->geometry("400x400+100+120");

&create_dropdown($mw);
my $mid_value;
$mid_value= \&create_dropdown_dit();
&create_dropdown_bot($mw);

#$ref = \&getGlobalName();

MainLoop;

sub create_dropdown {
    my $toplam  = shift;
    # Create dropdown and another element which shows my selection
    my $dropdown_value;
    my $dropdown = $toplam->BrowseEntry(
        -label => "Label",
        -variable => \$dropdown_value,
        )->place( -x => 100, -y => 15);
    my $showlabel = $toplam->Label(
        -text => "nothing selected",
        )->place( -x => 280, -y => 15);

    # Configure dropdown
    $dropdown->configure(
        # What to do when an entry is selected
        -browsecmd => sub {
            $showlabel->configure(-text => "You selected: $dropdown_value" ),
        },
    );

    # Populate dropdown with values
    foreach ( qw/apple banana pineapple grape/ ) {
        $dropdown->insert('end', $_);
    }
    # Set the initial value for the dropdown
    $dropdown_value = "Top value";
}



sub create_dropdown_bot {
    my $botlam  = shift;
    # Create dropdown and another element which shows my selection
    my $dropdown_value_bot;
    my $dropdownbot = $botlam->BrowseEntry(
        -label => "Label",
        -variable => \$dropdown_value_bot,
        )->place( -x => 100, -y => 75);
    my $showlabel = $botlam->Label(
        -text => "nothing selected",
        )->place( -x => 280, -y => 75);

    # Configure dropdown
    $dropdownbot->configure(
        # What to do when an entry is selected
        -browsecmd => sub {
            $showlabel->configure(-text => "You selected: $dropdown_value_bot" ),
        },
    );

    # Populate dropdown with values
    foreach ( qw/apple banana pineapple grape/ ) {
        $dropdownbot->insert('end', $_);
    }
    # Set the initial value for the dropdown
    $dropdown_value_bot = "Bottom value";
}


sub create_dropdown_dit {
    #my $di_thick  = shift;
    # Create dropdown and another element which shows my selection
    #my $di_thick_value;
    
    # A label to show what to type in
    my $label_wert = $mw->Label( 
        -text => 'mid value:',
    )->place( -x => 30, -y => 45);

    # This is the text-userinput field
    my $entry_wert = $mw->Entry( 
        # width is in characters, not pixel
        -width => 20,
    )->place( -x => 130, -y => 45);
    

    my $submit_but = $mw->Button(
    -text => "Execute",
    # call a sub somewhere
    -command => \&submit_action,
    )->place( -x => 130, -y => 135);
    
}




print $mid_value


Like mid_value i need to see after the loop.

Thanks in advance,
K.Vasanth
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to scp as different user in perl script

Hi, I am writing a perl script that needs to change to a another user and scp files to a remote server. The passwords should not be prompted but read from a config file. Please help. Thanks Sandeep (4 Replies)
Discussion started by: sdubey
4 Replies

2. Shell Programming and Scripting

create an user in perl

hi friends, i want to create an new user in my home directory , only just for checking. if it is possible, please help me. thanks (1 Reply)
Discussion started by: praneshbmishra
1 Replies

3. Post Here to Contact Site Administrators and Moderators

e-mail sent to user about PERL

Is there a way to setup an e-mail job (thru my account) to send me e-mail every time a new question or response to PERL is entered into a forum? thanks, djehresmann (1 Reply)
Discussion started by: djehresmann
1 Replies

4. Shell Programming and Scripting

Perl LWP user authentication

Hello all.. i am new to perl scripting.. i wanted to parse a text file, encode the parsed text and attach in url.. please point me to right resources if you know any..This is my major problem. Now i try to get a url running and save it in a text file using LWP module in perl, I used following... (0 Replies)
Discussion started by: empyrean
0 Replies

5. Shell Programming and Scripting

switch user from local user to root in perl

Hi Gurus, I have a script that requires me to switch from local user to root. Anyone who has an idea on this since when i switch user to root it requires me to input root password. It seems that i need to use expect module here, but i don't know how to create the object for this. ... (1 Reply)
Discussion started by: linuxgeek
1 Replies

6. Shell Programming and Scripting

User input - Perl need Help

If I want all user input to start with " : " if not display error or what I asking is how to do if statement that control a first letter of string that we want to start with. and not worry about the rest Thank (1 Reply)
Discussion started by: guidely
1 Replies

7. Shell Programming and Scripting

user input in perl?

Please tell me how to write a perl script that asks the user to enter words and that passes them to a variable. In bash, the "read" command would achieve such user interaction. #!/bin/bash read -p "Enter files: " vFiles However, I am looking for perl version of something equivalent... (2 Replies)
Discussion started by: LessNux
2 Replies

8. Shell Programming and Scripting

User input in perl code

Hello friends . I am newbie to perl scripting but still managed to write a code but i am stuck at a place where i need help . Below is the code and can someone help me in taking user input for changing the font size for a html table .Thank you in advance #!/bin/ksh echo " Enter the Directory... (4 Replies)
Discussion started by: ajayram_arya
4 Replies

9. Shell Programming and Scripting

User prompt for perl

perl -aF/\\t/ -lne 'BEGIN{%m=map{chomp;s/\cM|\cJ//g;$p=join("\t",(split/\t/));($p,$_)} <>;$m{"#CHROM\tINFO"}=$m{"Chr\tSegment Position"}};/SEGPOS=(\d+)/ || /\t(INFO)\t/ or next;$p=$F."\t".$1;exists $m{$p} and print join("\t",$_,$m{$p})' 12345_Marfan20_Output_Mutation_Report.txt <... (3 Replies)
Discussion started by: cmccabe
3 Replies

10. Shell Programming and Scripting

Perl to read user input

I am creating a bash that uses perl . The below code closes before the input is entered. If I run the perl as a .pl it is fine. What am I doing wrong? Thank you :). #!/bin/bash cd 'C:\Users\cmccabe\Desktop\wget' wget -O getCSV.txt http://xxx.xx.xxx.xxx/data/getCSV.csv print... (4 Replies)
Discussion started by: cmccabe
4 Replies
BrowseEntry(3)						User Contributed Perl Documentation					    BrowseEntry(3)

NAME
Tk::BrowseEntry - entry widget with popup choices. SYNOPSIS
use Tk::BrowseEntry; $b = $frame->BrowseEntry(-label => "Label", -variable => $var); $b->insert("end", "opt1"); $b->insert("end", "opt2"); $b->insert("end", "opt3"); ... $b->pack; SUPER-CLASS The "BrowseEntry" class is derived from the "Frame" class and inherits all the methods, options and subwidgets of its super-class. By default, options and methods are delegated to the entry subwidget. DESCRIPTION
BrowseEntry is a poor man's ComboBox. It may be considered an enhanced version of LabEntry which provides a button to popup the choices of the possible values that the Entry may take. BrowseEntry supports all the options LabEntry supports except -textvariable. This is replaced by -variable. Other options that BrowseEntry supports: -arrowimage Specifies the image to be used in the arrow button beside the entry widget. The default is an downward arrow image in the file cbxarrow.xbm -autolimitheight If set to a true value, then the height of the listbox will be at most the number of entries in the list. The overall maximum of "-listheight" still applies. -autolistwidth If set to a true value, then the width of the listbox will match the width of the largest entry. -browsecmd Specifies a function to call when a selection is made in the popped up listbox. It is passed the widget and the text of the entry selected. This function is called after the entry variable has been assigned the value. -browse2cmd Like "-browsecmd", but the callback is called with the listbox index instead of the selected value. -buttontakefocus Set the "-takefocus" option of the button subwidget. -choices Specifies the list of choices to pop up. This is a reference to an array of strings specifying the choices. -colorstate The state of the widget is reflected by color. A non-editable entry widget will get a light gray background, while an editable entry will be almost white. [This may change] -listcmd Specifies the function to call when the button next to the entry is pressed to popup the choices in the listbox. This is called before popping up the listbox, so can be used to populate the entries in the listbox. -listheight Set the height of the listbox. See also "-autolimitheight". -listwidth Specifies the width of the popup listbox. -state Specifies one of three states for the widget: normal, readonly, or disabled. If the widget is disabled then the value may not be changed and the arrow button won't activate. If the widget is readonly, the entry may not be edited, but it may be changed by choosing a value from the popup listbox. normal is the default. -style Set the "style" of the widget. Permitted values are "MSWin32" and "unix". By default "-style" is set to the current platform. Widgets with the "unix" style will look like a normal "BrowseEntry" widget, whereas with the "MSWin32" style the arrow will look close to the Windows' standard combobox widget, while moving the mouse the entries will be highlighted, and probably includes other changes. -variable Specifies the variable in which the entered value is to be stored. METHODS
insert(index, string) Inserts the text of string at the specified index. This string then becomes available as one of the choices. delete(index1, index2) Deletes items from index1 to index2. get The get method is delegated to the choices listbox. ADVERTISED WIDGETS
The following widgets are advertised: entry The entry widget. arrow The button with the arrow image. choices The toplevel widget containing the choice listbox. slistbox The scrolled listbox with the choices. SUBCLASSING
To make subclassing easier, the following methods may be overridden to use other standard widgets in composing the mega widget: LabEntryWidget A widget class compatible with Tk::LabEntry used for the entry. ButtonWidget A widget class compatible with Tk::Button used for the arrow button. ListboxWidget A widget class compatible with Tk::Listbox used for the choices listbox. For example to use a "NumEntry" widget (from the Tk-GBARR CPAN distribution) instead of the normal "Entry" widget: package Tk::NumBrowseEntry; use base qw(Tk::BrowseEntry); use Tk::NumEntry; Construct Tk::Widget 'NumBrowseEntry'; sub LabEntryWidget { "NumEntry" } BUGS
BrowseEntry should really provide more of the ComboBox options. AUTHOR
Rajappa Iyer rsi@earthling.net Chris Dean ctdean@cogit.com made additions. More additions by Slaven Rezic slaven@rezic.de This code was inspired by ComboBox.tcl in Tix4.0 by Ioi Lam and bears more than a passing resemblance to ComboBox code. This may be distributed under the same conditions as Perl. perl v5.12.1 2007-05-05 BrowseEntry(3)
All times are GMT -4. The time now is 05:39 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy