Is there a way to destroy the tkinter messagebox without clicking OK?

terratunaz picture terratunaz · Jan 6, 2016 · Viewed 14.1k times · Source

I know you can use something like, self.root.after(1000, self.update_clock)

But could I some how replace that second function with a function that's similar to messagebox.showinfo.destroy()? I'm basically trying to put these message boxes on a timer so that the user will see them but won't have to do anything themselves.

response = tkinter.messagebox.showinfo("Warning!", "New artist object has been     created: "
                                                       + "\n" + "$oid: " + str(self.artistObjectId))

if response == "ok":
            self.currentState += 1
            self.states[self.currentState](importedTracks[self.currentTrack])

Answer

BenJ picture BenJ · Jan 6, 2016

Maybe a message box is not what you require in this context. If you would just like to show a message then have it automatically disappear you could use a new TopLevel or frame and then destroy the frame after a timeout. In terms of user interaction and experience, message boxes are designed to wait for user input?

This is a good example of using a new TopLevel

closing tkmessagebox after some time in python

I found this page that describes what can be done to customise message boxes, though what I could find is somewhat limited.

http://effbot.org/tkinterbook/tkinter-standard-dialogs.htm