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

PySimpleGUI如何移除窗口默认灰色边框?

解决方案

PySimpleGUI 底层基于 Tkinter 实现,你可以直接通过 PySimpleGUI 提供的窗口配置参数结合底层 Tkinter 属性设置实现无边框效果,修改后的代码如下:

import PySimpleGUI as sg    

gifpath = "media/079.gif"
# 清除Image组件默认边距
image = sg.Image(gifpath, background_color='black', pad=(0,0))
layout = [[image]]
# 新增无边框、零边距、同背景色配置
window = sg.Window(
    'SCP-079',
    layout,
    size=(540, 360),
    icon='media/079.ico',
    no_titlebar=True, # 移除系统标题栏和边框
    margins=(0,0), # 清除布局默认内边距
    background_color='black', # 窗口背景和GIF背景一致
    grab_anywhere=True # 可选:无标题栏时可拖动窗口
)
# 清除Tkinter底层默认的边框厚度设置
window.TKroot.config(highlightthickness=0, bd=0)

while True:
    event, values = window.read(timeout=100)
    if event in (None,'Exit'):
        break
    image.update_animation_no_buffering(image.Filename, 100)

关键修改说明

  • no_titlebar=True:直接移除窗口默认的灰色边框和标题栏,是实现无边框的核心参数
  • margins=(0,0) + pad=(0,0):分别清除布局和图片组件的默认边距,避免边距位置露出默认灰色背景
  • 窗口与Image组件背景色统一设为黑色,避免出现颜色间隙
  • 底层window.TKroot.config配置:彻底移除Tkinter层残留的细边框配置

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.28 15:39:03