You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何去除Tkinter窗口的边框(含标题栏及侧边边缘)?

如何去除Tkinter窗口的边框及标题栏

当然有办法,Tkinter自带的overrideredirect()方法就能实现完全去除窗口的边框和标题栏,包括系统默认的侧边边缘和带按钮的标题栏。

核心实现代码

直接调用overrideredirect(True)即可禁用所有窗口装饰:

import tkinter as tk

root = tk.Tk()
# 开启无边框模式
root.overrideredirect(True)
# 设置窗口尺寸和初始位置
root.geometry("400x300+200+200")

# 添加测试组件验证效果
test_label = tk.Label(root, text="这是一个完全无边框的窗口", font=("Arial", 14))
test_label.pack(pady=80)

root.mainloop()

注意事项

  • 启用这个模式后,窗口会脱离系统窗口管理器的控制,意味着你没法用常规的拖动、最小化/最大化、关闭按钮操作,需要自己实现这些功能。
  • 如果之后想恢复窗口边框,调用overrideredirect(False)即可。

可选:实现窗口拖动功能

如果需要拖动无边框窗口,可以通过绑定鼠标事件来实现:

import tkinter as tk

root = tk.Tk()
root.overrideredirect(True)
root.geometry("400x300+200+200")

# 记录鼠标点击时的坐标
def on_mouse_down(event):
    root.click_x = event.x
    root.click_y = event.y

# 拖动窗口
def on_mouse_drag(event):
    new_x = root.winfo_x() + (event.x - root.click_x)
    new_y = root.winfo_y() + (event.y - root.click_y)
    root.geometry(f"+{new_x}+{new_y}")

# 绑定鼠标事件
root.bind("<ButtonPress-1>", on_mouse_down)
root.bind("<B1-Motion>", on_mouse_drag)

test_label = tk.Label(root, text="可拖动的无边框窗口", font=("Arial", 14))
test_label.pack(pady=80)

root.mainloop()

内容的提问来源于stack exchange,提问作者ihaveaproblem

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.12 21:30:32