i've a tkinter toplevel widget were you can choose ok or accept. it is created in a function: if you call that funtion the program should wait for a click on a button and than the function should return that choise, so that my function have the same use a the input
function in python 3. now my problem is: how can i pause my script until the user clicked on a button, so that all other files in my project pause (there happens nothing if the user clicks on a button in another tkinter window) are paused?
"""this is a script to alert a message in a tkinter toplevel window."""
from tkinter import Toplevel, Text, Button
import mouse as ms
root = None
def alert(msg, choice=False, button_a_msg="Ok", button_b_msg="cancel"):
try:
global root
if root is not None:
root.destroy() #make sure that there is no other duplicate of this window
clicked = False
chosen = None
root = Toplevel()
root.geometry("100x75")
text = Text(root)
text.insert("1.0", msg)
if choice:
button_a = Button(root, text=button_a_msg, command=lambda: [exec("clicked = True"), exec("chosen = 'a'")])
button_b = Button(root, text=button_b_msg, command=lambda: [exec("clicked = True"), exec("chosen = 'b'")])
else:
pass
text.config(state="disabled")
text.pack(expand=True, fill="both")
#insert code to wait here
return chosen
except Exception:
pass
i tried to find a function in the mouse module so i can set up a while loop and simply wait until mouse click and then check if a button is clicked, but it seems that that not exists.