python - 如何在不删除标题栏的情况下禁用 Tkinter 窗口的移动
问题描述
我一直在创建一个参加考试的应用程序。所以,为此,我必须做两件事。首先,禁用 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 和s创建自己的标题栏tkinter.Button
。我尝试使它与标题栏一起使用,但由于某种原因我无法重新调整窗口的焦点。
推荐阅读
- javascript - 如果组件在其渲染函数中返回null,为什么会触发componentDidMount?
- c# - c#将Json加载到继承的类中
- python - CodingBat Python make_chocolate 代码在“其他测试”中失败
- c++ - Qt moveToThread,带参数的信号/槽
- asp.net - ParamQuery 网格 (PQGrid) 将新行添加到嵌套网格
- javascript - Hyperledger Fabric - 存在历史注册表时,我们是否需要用户定义的事务模型?
- java - recyclerview 没有在键盘上方滚动以获取新消息
- r - 使用 R 中的 openair 包更改多面板泰勒图的字体大小
- android - 如何在 Datepicker 布局中显示有限的年数?
- ios - UITextView 高度不会改变