Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python 3 tkinter message box highlight the "No" button?

I want to create a message box that confirms the intent to delete.

    def delete_action(self):
    s_id = self.selected_ID_entry.get()
    s_name = self.seletedEntry.get()
    answer = messagebox.askquestion("Delete?","Are you sure you want to delete {}".format(s_name), icon='warning')

    if answer == 'yes':
        #deleted function here
    else:
        #not deleted function here

How to highlight the "No" button instead of the "Yes" button?

something like this

like image 855
Evan Avatar asked Aug 12 '18 00:08

Evan


1 Answers

You can set a default value as a keyword argument; something like this:

import tkinter as tk
from tkinter import messagebox

def quid():
    messagebox.askyesno("What", "What???????????", default='no')

root = tk.Tk()
ask = tk.Button(root, text='what?', command=quid)
ask.pack()
root.mainloop()
like image 61
Reblochon Masque Avatar answered Nov 02 '22 22:11

Reblochon Masque