0

I am trying to write a custom Yes/No confirmation message. I need to use specific font, button size etc. I would like it to be a function like zzz=myYesNoFunction('Please confirm your choice'). The problem is that my expresion z=questionYesNo() returns no value. Why?

import tkinter as tk
root = tk.Tk()
root.title("Main Window")
#custom messagebox code#########################################
m=""
def check(choice):
   global m
   if choice=="yes":
       message_window.destroy()
       m="YES"
   else:
       message_window.destroy()
       m="NO"
def questionYesNo():
   global message_window
   global m
   message_window = tk.Toplevel()
   message_window.title("This is Custom messagebox")
   label = tk.Label(message_window, text="Please confirm your choice.",
              font=("ariel 22 bold"), justify=tk.LEFT)
   label.pack(padx=20, pady=15)
   no = tk.Button(message_window, text="No", font=("ariel 15 bold"), width=8, 
        relief=tk.GROOVE, bd=3, command=lambda: check("no"))
   no.pack(padx=5, pady=10, side=tk.RIGHT)
   yes = tk.Button(message_window, text="Yes", font=("ariel 15 bold"), width=8, 
         relief=tk.GROOVE,
             bd=3, command=lambda: check("yes"))
   yes.pack(pady=10, side=tk.RIGHT)
   return m
#end of custom messagebox code#########################################
text = tk.Label(root, text="Click on Open button to \nopen questionYesNo window", font=("ariel 20 bold"))
text.pack(padx=30, pady=5,side=tk.TOP)
choicetobeconfirmed = tk.Button(root, text="Open", font=("ariel 20 bold"), width=10,
                relief=tk.GROOVE, bd=2, bg='black',fg="gold2", command=questionYesNo)
choicetobeconfirmed.pack(padx=30, pady=15)
z=questionYesNo()
print(z)
root.mainloop()
rpieka
  • 1
  • 1
  • Your question is a bit unclear - it _does_ return a value. It's just that the value is an empty string. Are you asking how to make the dialog wait until you've clicked a button? – Bryan Oakley Jan 24 '22 at 22:47
  • I would like the program to wait for my choice and go forward printing it on the screen. So maybe the problem is that the program doesn't wait for my answer (tkinter button click) and goes on with the empty value. What to do to force it to wait? – rpieka Jan 24 '22 at 22:50
  • Help, please... – rpieka Jan 25 '22 at 18:02
  • did you follow the link to the duplicate question? It has an example of how to get a dialog to wait. – Bryan Oakley Jan 25 '22 at 19:32

0 Answers0