python-3.x - Tkinter 专注于弹出窗口

标签 python-3.x tkinter

我有一个关于主窗口弹出窗口的问题。我如何确保当有弹出窗口(设置日期和时间)时,在用户关闭弹出窗口之前不能触摸主窗口(即关闭或按任何东西)。

我已经尝试使用 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/

相关文章:

python-3.x - 检查两个数据帧的相等性

python - 实现子表(查看表): designing class relationship

python - Tkinter 全局绑定(bind)

python - 删除由多个 tkinter 小部件组成的对象

python - 需要对部分正则表达式代码的具体解释

python - iterrows() 需要几个小时才能运行,如何加快速度?

python 如何使用中序/前/后/无递归遍历二叉搜索树?

python - 从文本文件中按列打印列表

user-interface - Python-使用 ttk.Style 找出可以/不能更改的值

python - 在 REAPER 嵌入式环境下运行 tkinter GUI