overrideredirect() 有什么作用? [英] What does overrideredirect() do?

查看:27
本文介绍了overrideredirect() 有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始了解 overrideredirect 有助于移除默认的窗口装饰,例如工具栏.它还有什么其他用途?我不太确定,找不到太多文档.

我在 mac 上工作.使用 tkinter 我想获得保持 maxsize 且无法调整大小的窗口,这是我使用 geometryresizable 实现的.我现在需要的是保证我的用户没有随机击键可以关闭窗口.overrideredirect 会帮助我吗?有什么办法吗?

I have come to understand overrideredirect helps removing the default window decorations like the toolbar.What are its other uses? I am not very sure and couldn't find much documentation.

I am working on a mac. Using tkinter I want to obtain window which remains maxsize and cannot be resized,which i have achieved using geometry and resizable. What I need now is the guarantee that no random keystrokes by my user can close the window. Will overrideredirect help me in that? Is there any alternative?

推荐答案

您可以使用 overrideredirect() 并将其标志设置为 True.这将禁止您的窗口以常规方式关闭,如上面链接中所述.常规方式,是指X按钮和Alt + F4按键组合.

You can use overrideredirect() and set its flag to True. This will disable your window to be closed by regular means as mentioed in the link above. By regular means, it is meant the X button and the Alt + F4 keystrokes combination.

由于您使用了 geometry()resizable(),您将需要调用 update_idletasks() to强制在应用程序下一次空闲之前更新显示.

Since you used geometry() and resizable(), you will need to call update_idletasks() to force the display to be updated before the application next idles.

这是一个例子:

import Tkinter as Tk

root = Tk.Tk()
root.geometry('200x200+100+100')
root.resizable(False, False)
root.update_idletasks()
root.overrideredirect(True)
root.mainloop()

此方法的缺点:它始终适用于 Microsoft Windows 平台,但可能不适用于某些 Unix 和 MacOS 平台.

Drawback of this method: it always works on Microsoft Windows platform but it may not work on some Unix and MacOS platforms.

您询问了有关 update_idletasks() 的说明,我认为最好直接从其文档中引用,因为它更清楚(但如果您不理解此引用,请告诉我):

You asked clarification about update_idletasks(), I think it is better if I quote directly from its documentation as it is clearer (but if you do not understand this quotation, please let me know):

更新显示的一些任务,例如调整大小和重新绘制小部件,被称为空闲任务,因为它们通常被推迟到应用程序已完成处理事件并返回到等待新事件的主循环.

Some tasks in updating the display, such as resizing and redrawing widgets, are called idle tasks because they are usually deferred until the application has finished handling events and has gone back to the main loop to wait for new events.

如果你想在应用程序下一次空闲之前强制更新显示,调用 w.update_idletasks() 方法在任何小部件.

If you want to force the display to be updated before the application next idles, call the w.update_idletasks() method on any widget.

这篇关于overrideredirect() 有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆