Russell Borogove
Russell Borogove

Reputation: 19037

getting keyboard back from tkinter

I'm working on a graphical app, and at the start of the run I'd like to ask the user a single configuration question. The graphical framework (Panda3D) has ugly default dialog boxes, so I'd like to use something like tkInter to provide a modal dialog. I tried this:

import Tkinter
import tkMessageBox

root = Tkinter.Tk()
# hide the root window
root.withdraw()

config.PLAY_MUSIC = tkMessageBox.askyesno( "My App", 
       "Would you like this app to play music from your iTunes collection?" )

root.destroy()

This does what I want it to, but it appears to route all further keyboard events to tkInter rather than my Panda3D app. I don't need to do anything further with tk after this dialog.

I can put the tk dialog into a separate app that chains onto mine, I suppose, but I'm wondering if there's a way to kill tk and get the keyboard back without exiting my app entirely.

Update: Tried root.quit(), which does seem to get the keyboard back, but I get a "Fatal Python error: PyEval_RestoreThread: NULL tstate" crash on exit from my program, which isn't ideal.

Upvotes: 2

Views: 432

Answers (1)

Marlen T. B.
Marlen T. B.

Reputation: 874

Have you tried:

grab_release(self)
Which does: Release grab for this widget if currently set.

Where "A grab directs all events to this and descendant widgets in the application."

as in:

root.grab_release()

Hope you haven't tried this one.

Upvotes: 2

Related Questions