Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to create hotkeys with Tk? 1

Status
Not open for further replies.

kmarris

Programmer
Jan 25, 2007
12
0
0
US
I know Perl, but I don't know Tk. I have a Perl script that someone else wrote. When it runs, there is a GUI with an Exit button.

Rather than click the Exit button, I want to assign a keyboard shortcut to exit the GUI. Can someone tell me how to add this functionality to the Perl script?
 
Hi

Code:
[gray]# Tcl[/gray]

[b]button[/b] .be [b]-text[/b] [i]Exit[/i] [b]-underline[/b] [i]1[/i] [b]-command[/b] [i]exit[/i]
[b]pack[/b] .be

[b]bind[/b] . [i]<Alt-Key-x>[/i] [i]exit[/i]
Code:
[gray]# Perl[/gray]

[b]use[/b] Tk;

$wi=[b]MainWindow[/b]->[b]new[/b];
$be=$wi->[b]Button[/b]([b]-text[/b]=>[i]"Exit"[/i],[b]-underline[/b]=>[i]"1"[/i],[b]-command[/b]=>[i]"exit"[/i]);
$be->[b]pack[/b];

$wi->[b]bind[/b]([i]"<Alt-Key-x>"[/i]=>[i]"exit"[/i]);

[b]MainLoop[/b];

Feherke.
 
Thanks, Feherke. That worked perfectly.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top