#!/usr/bin/perl use warnings; use strict; use Tk; use Tk::LabFrame; my $password; my $hide = 'Y'; my $revert = 0; my $char; # Utworzenie nowego okna my $mw = MainWindow->new; # Utworzenie elementow my $copy_button = $mw->Button( -text => 'Kopiuj', -command => \©_text); my $password_entry = $mw->Entry( -textvariable => \$password, -show => '*'); my $info_label = $mw->Label( -text => 'Informacja'); my $hide_lf = $mw->LabFrame( -label => 'Ukryj tekst'); my $hide_y = $hide_lf->Radiobutton( -text => 'Tak', -value => 'Y', -variable => \$hide, -command => \&password_entry_show); my $hide_n = $hide_lf->Radiobutton( -text => 'Nie', -value => 'N', -variable => \$hide, -command => \&password_entry_show); my $revert_cb = $mw->Checkbutton( -text => 'Odwroc', -variable => \$revert); my $char_om = $mw->Optionmenu( -options => [['asterisk (*)' => '*'], '%'], -variable => \$char, -command => \&password_entry_show); my $alter_lb = $mw->Listbox( -height => 3); $alter_lb->insert('end', 'Bez zmian', 'male litery', 'WIELKIE LITERY'); $alter_lb->selectionSet(0); my $menu = $mw -> Menu(); $mw->configure(-menu => $menu); my $file_menu = $menu->cascade( -label => '~Plik'); $file_menu->command( -label => '~Otworz', -command => \&menu_file_open); $file_menu->separator; $file_menu->command( -label => 'Za~koncz', -command => \&menu_file_quit); # Umiejscowienie elementow w oknie $copy_button->grid(-row => 1, -column => 2, -sticky => 'ew'); $password_entry->grid(-row => 1, -column => 1, -sticky => 'ew'); $info_label->grid(-row => 2, -column => 1, -sticky => 'ew'); $hide_lf->grid(-row => 1, -column => 3, -sticky => 'nsew', -rowspan => 2); $hide_y->grid(-row => 1, -column => 1, -sticky => 'nsew'); $hide_n->grid(-row => 2, -column => 1, -sticky => 'nsew'); $revert_cb->grid(-row => 2, -column => 2, -sticky => 'ew'); $char_om->grid(-row => 3, -column => 3, -sticky => 'ew'); $alter_lb->grid(-row => 3, -column => 2, -sticky => 'nsew'); $mw->gridRowconfigure(2, -weight=> 1); $mw->gridRowconfigure(3, -weight=> 2); $mw->gridColumnconfigure(1, -weight=> 1); $hide_lf->gridRowconfigure(1, -weight=> 1); $hide_lf->gridRowconfigure(2, -weight=> 1); $mw->bind('', \&menu_file_quit); # Wkaczenie glownej petli MainLoop; my $after_id; sub copy_text { my $text = $password; $text = lc $password if (($alter_lb->curselection)[0] == 1); $text = uc $password if (($alter_lb->curselection)[0] == 2); $text = join '', reverse split //, $text if $revert; $info_label->configure(-text => $text); $mw->afterCancel($after_id); $after_id = $mw->after(5000, sub { $info_label->configure(-text => scalar localtime); }); } sub password_entry_show { $password_entry->configure(-show => ($hide eq 'Y' ? $char : undef)); $char_om->configure(-state => ($hide eq 'Y' ? 'normal' : 'disabled')) if defined $char_om; } sub menu_file_open { my $f = $mw->getOpenFile(-filetypes => [ ['Skrypty w Perlu', '.pl'], ['Wszystkie pliki', '*']]); return unless defined $f; $password = $f; } sub menu_file_quit { exit if 'Yes' eq $mw->messageBox( -message => 'Quit?', -type => 'YesNo', -default => 'No', -icon => 'question', -title => 'Quit'); }