Note that there are some explanatory texts on larger screens.

plurals
  1. POBinding buttons to Alt keypresses?
    primarykey
    data
    text
    <p>I've got a simple Tkinter application I've written, with a few buttons at the bottom of a form. My goal is to follow the standard convention of underlining a letter on the button, and binding an action for that letter with the Alt key (ie: Alt-s for "_S_ave").</p> <p>I've tried making a root window binding to "Alt-s", "Alt-KeyPress-s", and "Mod1-s", and none seem to work reliably. They sometimes fire, but even though I have "return break" on my event function the "s" letter is propagating to the entry widget.</p> <p>I believe this is an issue with Linux/X11 and Mod1 vs Alt handling because Control key bindings work consistently. I haven't been able to locate any best practices for working around the issue, thus my appeal here.</p> <p>Can someone share how to get an Alt key binding working in Linux/X11?</p> <p>** Updated with a sample</p> <pre><code>from Tkinter import * class GUI: def __init__(self,root): self.root = root e = Entry(self.root) e.grid(column=0,row=0) b = Button(self.root, text="Save", underline = 0) b.grid(column=0,row=1) root.bind("&lt;Alt-s&gt;",self.save) e.focus() def save(self,event=None): print("Hey, you pressed Alt-s!") return "break" root = Tk() App = GUI(root) print("At this point, pressing Alt-s places the s string in the entry widget, and doesn't trigger") root.mainloop() </code></pre> <p>** Update 2</p> <p>I've had a few reviewers let me know this works on their system, even Linux. Perhaps there's a problem with my tiling wm or other configuration for X11, however I've had no problems using Alt with any other X11 GUI apps.</p> <p>I'm open to suggestions on how to troubleshoot this.</p> <p>** Update 3</p> <p>I've been reviewing the behavior with xmodmap, and it appears that when I assign Alt_R the Tk keybindings stop working. The events reported by xev match verbatim, and yet Tk's behavior changes. Still digging.</p> <p>** Update 4</p> <p>Mr. Lange on the Tkinter list found a link that helps explain similar behavior, at <a href="https://bbs.archlinux.org/viewtopic.php?id=58145" rel="nofollow">https://bbs.archlinux.org/viewtopic.php?id=58145</a> .</p> <p>I've made that change to my xmodmap, and now Alt works as expected. I can't explain why binding Alt_R to mod4 would effect Alt_L, or why it would only effect Tk applications.</p> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload