# Test to enter select directory with gui # Good to use next 3 lines for all perl programs. #! /usr/bin/perl use warnings; use strict; # Use Tk module for gui and create window use Tk; my $mw = new MainWindow; use Encode; #so can read directories #Button to open directory and see tissue types my $tissue="plasma";#default value my $tissue_but = $mw -> Button(-text => 'Tissue Type', -command =>sub {select_tissue()}); $tissue_but->grid(-row=>3,-column=>1); #-command => [ sub { ... }, arg1, arg2, ... ] #Button to close gui window my $but=$mw -> Button(-text => 'Data Entry Complete', -command =>sub {do_end()}); $but->grid(-row=>10,-column=>1); #This must be at the end of every Tk section MainLoop; sub select_tissue { my $dir=$mw-> chooseDirectory(-initialdir =>'Z:\Projects\RunMSMS\MGF\human\ion_trap'); $dir = encode("windows-1252", $dir); my @fulldir=split(/\//,$dir);#split out tissue type from full directory my $tis=$fulldir[6]; return $tis; } sub do_end # { my ($tissue)=@_; open INFO_OUT, ">>test_gui_output.txt" or die $!; print INFO_OUT "$tissue\n"; exit; #close gui window }