Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change words on tkinter Messagebox buttons

I'm using tkinter's "askokcancel" message box to warn the user, with a pop-up, of an irreversible action.

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

I'd like to change the text of the 'OK' button (from 'OK') to something like 'Delete', to make it less benign-looking.

Is this possible?

If not, what is another way to achieve it? Preferably without introducing any dependancies...

like image 899
Emilio M Bumachar Avatar asked Apr 26 '13 18:04

Emilio M Bumachar


1 Answers

Why not open a child window thus creating your own box with your own button like this:

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()
like image 117
Yousef_Shamshoum Avatar answered Oct 06 '22 17:10

Yousef_Shamshoum