#!/usr/bin/perl -w use strict; use Wx; MyApp->new->MainLoop; package MyFrame; use Wx qw[:everything]; use base 'Wx::Frame'; my $abbruch; sub new { my $class = shift; my $frame = $class->SUPER::new( undef, -1, 'StopLoop', [-1, -1], [175, 150] ); $frame->{panel} = Wx::Panel->new( $frame, -1 ); $frame->{bt_start} = Wx::Button->new( $frame->{panel}, -1, 'starten', [-1, -1], [150, -1] ); $frame->{txt_status} = Wx::TextCtrl->new( $frame->{panel}, -1, "", [-1, -1], [150, -1] ); $frame->{bt_stop} = Wx::Button->new( $frame->{panel}, -1, 'abbrechen', [-1, -1], [150, -1] ); $frame->{sizer_2} = Wx::BoxSizer->new(wxVERTICAL); $frame->{sizer_2}->Add($frame->{bt_start}, 0, wxALL|wxALIGN_CENTER_HORIZONTAL, 10); $frame->{sizer_2}->Add($frame->{txt_status}, 0, wxALL|wxALIGN_CENTER_HORIZONTAL, 10); $frame->{sizer_2}->Add($frame->{bt_stop}, 0, wxALL|wxALIGN_CENTER_HORIZONTAL, 10); $frame->{panel}->SetSizer($frame->{sizer_2}); Wx::Event::EVT_BUTTON($frame, $frame->{bt_start}->GetId, \&starte_schleife); Wx::Event::EVT_BUTTON($frame, $frame->{bt_stop}->GetId, \&abbrechen_schleife); return $frame; } sub starte_schleife{ my $frm = shift; undef($abbruch); for my $i(1..10000) { $frm->{txt_status}->SetValue("$i. Schleifendurchlauf"); $frm->{txt_status}->Update; Wx::Yield(); last if $abbruch; } } sub abbrechen_schleife{ my $frm = shift; $abbruch = 1; } package MyApp; use base 'Wx::App'; sub OnInit { MyFrame->new->Show(1) }