This is the last tutorial on Tkinter, there are still lots of widgets that I have not been able to cover on this website and you can find all of them on the official webpage of Tkinter!
In this example tutorial I am going to create a message box that will return the answer from the user after the user has either clicked on the yes or the no button on the message box.
This example is not that different from the previous one except this time I have created the yes or no message box instead of the normal message box.
def showHello(): if chVarName.get() == 1: pass else: hello_label.configure(text=helo.get() + " " + slogan.get()) # change the text inside the label yesno = msgbox.askyesno("Hello World", "Hello Again World?") # message box will get answer from user print(yesno)
As you can see if the user has clicked on the button and the check box has been unchecked (refer to the previous program) then the above function will create the message box which will print the output depending on whether the user has clicked on the yes or the no button.
The outcome is as follows:-
If I pressed the Yes button then the message box will return True or else if I pressed the No button then it will return false and exit accordingly.