使用 TCL 扩展在 Tkinter 中设置本机窗口样式
pythonware.com/library/tkinter/introduction/... 记录一个 overrideredirect 方法 这将删除标题栏和 边界,如果这还不够你 必须设置本机窗口样式,我是 不确定 Tkinter 是否给你这个 一种低级访问,如果没有,请尝试 像这样的东西 twapi.magicsplat.com/ui.html#set_window_style TCL延伸
在之前的一篇文章中,我得到了这个作为关于如何在 Tkinter 中获得类似于下图的边框的回复。我不熟悉 Tcl 及其扩展。那么该怎么做呢?最终目标基本上是获得 Tkinter 窗口下方的边框。
编辑:
我在Windows 7上使用了以下内容,它似乎没有改变样式。它可能缺少一些东西。任何帮助将不胜感激,这真的很酷!
import string, win32ui, win32con
import Tkinter as tk
root = tk.Tk()
frame = win32ui.CreateWindowFromHandle(string.atoi(root.wm_frame(), 0))
frame.ModifyStyle(win32con.WS_CAPTION, 0, win32con.SWP_FRAMECHANGED)
root.mainloop()
pythonware.com/library/tkinter/introduction/…
documents a overrideredirect method
that will remove thetitlebar and
borders, if that is not enough you
must set the native window style, I'm
not sure if Tkinter gives you that
kind of low-level access, if not, try
the something like
twapi.magicsplat.com/ui.html#set_window_style
TCL extension
In an earlier post I got this as a reply on how to get a border in Tkinter similar to the one pictured below. I am not familiar with Tcl and it's extensions. So how would go about doing this? The end goal is basicaly to get the border below on a Tkinter window.
Edit :
I used the following on Windows 7 and it didn't seem to change the style. It's probably missing something. Any help would be appreciated, this could be really cool!
import string, win32ui, win32con
import Tkinter as tk
root = tk.Tk()
frame = win32ui.CreateWindowFromHandle(string.atoi(root.wm_frame(), 0))
frame.ModifyStyle(win32con.WS_CAPTION, 0, win32con.SWP_FRAMECHANGED)
root.mainloop()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以结合使用 Python win32 api 包和 Tkinter 来完成此操作。您需要知道的是 Tk 窗口是 Win32 窗口的客户端部分。窗口管理器交互是使用 Tk 窗口本身的父级包装器来处理的。如果您有一个 Tkinter 窗口“w”,那么您可以为该框架创建一个 PyWin32 窗口或直接操作它。您可以使用 w.wm_frame() 并解析返回的十六进制字符串或通过对 Tk 窗口中的 winfo_id 值使用 GetParent 来获取帧 hwnd(尽管 wm_frame 可能更可靠)。
这会删除 WS_CAPTION 样式并通知窗口其框架已修改,这会强制重新计算几何图形,以便更改传播到 Tk 子窗口。
编辑 - -
下面的安排是为了确保我们在窗口完全创建并映射到显示器之后修改窗口样式。
You can do this using a combination of the Python win32 api packages and Tkinter. What you need to know is that a Tk window is the client section of a Win32 window. The window manager interactions are handled using a wrapper that is the parent of Tk window itself. If you have a Tkinter window 'w' then you can create a PyWin32 window for the frame or just manipulate it directly. You can get the frame hwnd using w.wm_frame() and parsing the hex string returned or by using GetParent on the winfo_id value from the Tk window (although wm_frame is likely to be more reliable).
This removes the WS_CAPTION style and notifies the window that its frame is modified which forces a geometry recalculation so that the change propagates to the Tk child window.
EDIT ---
The following arranges to ensure we modify the window style after the window has been fully created and mapped to the display.
一种解决方案是绘制自己的边界。使用overrideredirect删除所有装饰,网格/打包/放置填充窗口的画布,然后绘制或使用位图以获得您想要的视觉效果。您必须添加自己的绑定来移动窗口和调整窗口大小,但这并不太困难。
One solution is to draw your own border. Use
overrideredirect
to remove all decorations, grid/pack/place a canvas that fills the window, then draw or use bitmaps to get the visual effect you want. You'll have to add your own bindings for moving and resizing tne window, but that's not too difficult.