LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-18-2018, 11:43 PM   #1
Roihan
LQ Newbie
 
Registered: Jan 2018
Location: Surakarta, Central Java, Indonesia
Distribution: MX-Linux, Debian, Arch Linux
Posts: 12

Rep: Reputation: Disabled
Python : How to bind tkinter widget to numeric enter key


I'm creating a simple python program and I need to bind my tkinter widget to the right enter key (the one which is located in the keyboard numeric pad)

I've browsed google and found the <Return> key binding but it works only for the main enter key.

I really need it because my users will use the numeric keypad for the main operation.

Thanks for any help
 
Old 10-19-2018, 11:43 AM   #2
RockDoctor
Senior Member
 
Registered: Nov 2003
Location: Minnesota, US
Distribution: Fedora, Ubuntu, Manjaro
Posts: 1,773

Rep: Reputation: 422Reputation: 422Reputation: 422Reputation: 422Reputation: 422
Have not tried using it in Python, but xev shows keysym 0xff0d for the return key by the alpha keys, and 0xff8d for the keypad return key
 
1 members found this post helpful.
Old 10-21-2018, 09:49 AM   #3
Beryllos
Member
 
Registered: Apr 2013
Location: Massachusetts
Distribution: Debian
Posts: 529

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
The key is called KP_Enter. See this reference:

http://infohost.nmt.edu/tcc/help/pub...key-names.html

(found by googling "python tkinter bind numeric return"
The table contains much more that may interest you.)

Last edited by Beryllos; 10-21-2018 at 01:46 PM.
 
1 members found this post helpful.
Old 10-21-2018, 10:25 AM   #4
average_user
Member
 
Registered: Dec 2010
Location: Warsaw, Poland
Distribution: Slackware
Posts: 536

Rep: Reputation: 216Reputation: 216Reputation: 216
It's also KP_Enter according to xev:
Code:
KeyRelease event, serial 36, synthetic NO, window 0x1e00001,
    root 0xd6, subw 0x0, time 1807948071, (1003,272), root:(2923,272),
    state 0x0, keycode 104 (keysym 0xff8d, KP_Enter), same_screen YES,
"   XLookupString gives 1 bytes: (0d) "
    XFilterEvent returns: False
It probably stands for Keypad Enter.
 
1 members found this post helpful.
Old 10-21-2018, 02:15 PM   #5
Beryllos
Member
 
Registered: Apr 2013
Location: Massachusetts
Distribution: Debian
Posts: 529

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
Besides looking it up online, another way to discover the name of the key is to inspect the event.keysym attribute in the event handler. Here is a Python 2 program which works for almost any key pressed:

Code:
from Tkinter import *

root = Tk()

def key(event):
    print "pressed", event.keysym

def callback(event):
    frame.focus_set()
    print "clicked at", event.x, event.y

frame = Frame(root, width=100, height=100)
frame.bind("<Key>", key)
frame.bind("<Button-1>", callback)
frame.pack()

root.mainloop()
Typical output:
Code:
$ python2 keypress.py
clicked at 71 58
pressed 'a'
pressed 'semicolon'
pressed 'Return'
pressed 'KP_Enter'
pressed 'KP_Down'
pressed 'KP_Next'
pressed 'Shift_L'
pressed 'Shift_R'
pressed 'Caps_Lock'
pressed 'Control_L'
pressed 'Alt_R'
pressed 'Super_R'
With my particular desktop (gnome 3), this program does not report the PrintScreen button, and only reports the left "Windows Logo" key (keysym Super_L) when Shift, Alt, or Control is pressed at the same time.
 
2 members found this post helpful.
Old 10-24-2018, 06:48 AM   #6
Roihan
LQ Newbie
 
Registered: Jan 2018
Location: Surakarta, Central Java, Indonesia
Distribution: MX-Linux, Debian, Arch Linux
Posts: 12

Original Poster
Rep: Reputation: Disabled
It works well with KP_Enter. I'll learn about xev soon.
Thanks for everybody.
 
  


Reply

Tags
binding, python, tkinter


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Python : How to update the value of a Tkinter widget after user input Asciente Programming 3 11-21-2017 05:56 AM
[SOLVED] Python tkinter, problem when using pack_forget to remove widget srinietrx Programming 3 05-29-2015 07:59 AM
Text widget in Tkinter(Python on Win 7) not getting updated simultaneously!!! B Akshay Programming 1 02-08-2013 10:49 AM
TKinter text widget clear rockharley Linux - Newbie 4 08-15-2012 08:50 PM
basic python entry tkinter widget how-to donnied Programming 2 03-30-2008 10:36 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration