How would I make it it so a pop up box (If you have better name for it comment below) appear asking you a question. It would have one button saying I agree and another saying I disagree.
1 Answer
Here’s a simple one I suppose:
import tkinter as tk
root = tk.Tk()
questionsAsked = []
def yes():
#do stuff if the user says yes
pass
def no():
#do stuff if the user says no
pass
def modal(question):
if question in questionsAsked:
return False
questionsAsked.append(question)
label = tk.Label(root, text=question)
bYes = tk.Button(root, text="Yes", command=yes)
bNo = tk.Button(root, text="No", command=no)
for el in [label, bYes, bNo]:
el.pack()
modal("Do you want to continue?")
root.mainloop()
3 Comments
elmuscovado
How would you make it so it only asks it once (thanks for the help!)
rassar
What do you mean by “only asks once”? Do you mean the same question can’t be asked multiple times? Or do you mean that the window closes after the user selects an option?
rassar
Hmmm...I would probably need to see more of your code to make it work, but I’ll put an example up.
tkintermodule?