Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7500327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:08:33+00:00 2026-05-29T20:08:33+00:00

I’ve got a simple Tkinter application I’ve written, with a few buttons at the

  • 0

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”).

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.

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.

Can someone share how to get an Alt key binding working in Linux/X11?

** Updated with a sample

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("<Alt-s>",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()

** Update 2

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.

I’m open to suggestions on how to troubleshoot this.

** Update 3

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.

** Update 4

Mr. Lange on the Tkinter list found a link that helps explain similar behavior, at https://bbs.archlinux.org/viewtopic.php?id=58145 .

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.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T20:08:34+00:00Added an answer on May 29, 2026 at 8:08 pm

    The answer is that modifying Alt_R to bind it to the Windows key (Mod4) was the root cause of the problem. I believe that made Alt_L work as Mod1 though it was explicitly not modified in xmodmap. Therefor it must have broken some implied behavior, but only for Tk apps.

    From the Arch BBS link modifying the Alt_R keycode to trigger Super_L resolved the behavior. So now Alt_R functions as the Windows key, but Tk doesn’t notice any changes with Alt_L.

    Root bindings for Alt now work appropriately without double binding, because Entry widgets ignore Alt keypresses by default. With proper Alt behavior, not only are the Alt key bindings working, but the return break behavior isn’t required either.

    I did not see default ignore bindings for Mod1 keys in any widget, and if Alt_L suddenly decided to present Mod1 that does explain the behavior where Mod1 bindings would fire, but a double binding was required to prevent the Entry widget from getting the key.

    ~/.Xmodmap for reference:

    ! ISO_Level3_Shift is what xev reports for my right Alt key
    ! mod4 is the Windows key modifier, and tied to WM operations
    
    ! Trying a different approach documented at
    ! https://bbs.archlinux.org/viewtopic.php?id=58145
    keycode 108 = Super_L
    remove mod1 = Super_L
    

    What a messy problem, altering an undocumented implied behavior through an indirect change…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
i got an object with contents of html markup in it, for example: string
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm making a simple page using Google Maps API 3. My first. One marker
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.