Change words in tkinter message buttons

I am using the tkinter "askokcancel" message box to warn the user about an irreversible action popup.

from tkinter import Tk Tk().withdraw() from tkinter.messagebox import askokcancel askokcancel("Warning", "This will delete stuff") 

I want to change the text of the OK button (from OK) to Delete to make it less benign.

Is it possible?

If not, what other way to achieve? Preferably without introducing any dependencies ...

+4
source share
2 answers

No, there is no way to change the button text for inline dialogs.

Your best option is to create your own dialogue. This is not very difficult to do, and it gives you absolute control over what is in the widgets of the dialog box.

+4
source

Why not open the child window by creating your own block using your own button:

 from tkinter import * def messageWindow(): win = Toplevel() win.title('warning') message = "This will delete stuff" Label(win, text=message).pack() Button(win, text='Delete', command=win.destroy).pack() root = Tk() Button(root, text='Bring up Message', command=messageWindow).pack() root.mainloop() 
+7
source

All Articles