我有一个关于主窗口弹出窗口的问题。我如何确保当有弹出窗口(设置日期和时间)时,在用户关闭弹出窗口之前不能触摸主窗口(即关闭或按任何东西)。
我已经尝试使用 grab_set
但主窗口仍然可以关闭,导致错误消息:
bgerror failed to handle background error.
grab_set_global
对我有用,但我无法移动弹出窗口。
# Main window
root = Tk()
root.title("Restaurants")
root.geometry("800x500")
lines of codes..... where user will select if they want to set the date
and time
# Popup window
def date_time():
popup = Tk()
popup.title("Set Date and Time")
popup.geometry("500x500")
popup.grab_set() # Not working
lines of codes to run
我想让它聚焦在弹出窗口上,并且在弹出窗口关闭/销毁之前,它下面的主窗口将无法关闭。
最佳答案
您可以使用 popup.focus_force
,但可能首先检查 root 是否处于焦点。但这似乎类似于作弊。
关于python-3.x - Tkinter 专注于弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58709452/