Skip to content Skip to sidebar Skip to footer

Tkinter Button Doesn´t Change It´s Relief After Pressing It

Why does my tkinter Button stays in the 'sunken' relief after I press it? import tkinter from tkinter import messagebox as msgbox class GUI(object): def __init__(self):

Solution 1:

Your callback is printing "raised" because your code is run before the default button bindings, so the button relief is in fact raised at the point in time when your function is called.

I'm pretty sure this is what is causing the button to stay sunken:

  1. you click on the button, and a dialog appears. At this point the button is raised because tkinter's default binding has not yet had a chance to run , and it is the default bindings which cause the button to appear sunken
  2. a dialog appears, which steals the focus from the main window.
  3. you click and release the button to click on the dialog. Because the dialog has stolen the focus, this second release event is not passed to the button
  4. at this point the processing of the original click continues, with control going to the default tkinter binding for a button click.
  5. the default behavior causes the button to become sunken
  6. at this point, your mouse button is not pressed down, so naturally you can't release the button. Because you can't release the button, the window never sees a release event.
  7. Because the button never sees a button release event, the button stays sunken

For a description of how tkinter handles events, see this answer: https://stackoverflow.com/a/11542200/7432. The answer is focused on keyboard events, but the same mechanism applies to mouse buttons.

Post a Comment for "Tkinter Button Doesn´t Change It´s Relief After Pressing It"