gpt4 book ai didi

python - 如何在不删除标题栏的情况下禁用 Tkinter 窗口的移动

转载 作者:行者123 更新时间:2023-12-04 07:47:47 25 4
gpt4 key购买 nike

我一直在创建一个应用程序来参加考试。所以,为此,我必须做两件事。
首先,禁用 Tkinter 窗口的拖动,不要让用户关注其他窗口而不是我的应用程序窗口。这意味着我想让我的应用程序在使用我的应用程序时不能使用其他应用程序。

最佳答案

尝试这个:

import tkinter as tk


class FocusedWindow(tk.Tk):
def __init__(self, **kwargs):
super().__init__(**kwargs)

# Force it to be unminimisable
super().overrideredirect(True)

# Force it to always be on the top
super().attributes("-topmost", True)

# Even if the user unfoceses it, focus it
super().bind("<FocusOut>", lambda event: self.focus_force())

# Take over the whole screen
width = super().winfo_screenwidth()
height = super().winfo_screenheight()
super().geometry("%ix%i+0+0" % (width, height))


root = FocusedWindow()
# You can use it as if it is a normal `tk.Tk()`
button = tk.Button(root, text="Exit", command=root.destroy)
button.pack()
root.mainloop()
这删除了标题栏,但您始终可以使用 tkinter.Label 创建自己的标题栏。 s 和 tkinter.Button s。我尝试让它与标题栏一起工作,但由于某种原因我无法重新聚焦窗口。

关于python - 如何在不删除标题栏的情况下禁用 Tkinter 窗口的移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67136261/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com