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

使用CustomTkinter实现全屏窗口异常:无法覆盖整个屏幕?

CustomTkinter全屏无法覆盖整个屏幕的解决方法

问题描述

我正在使用CustomTkinter开发应用,希望实现全屏效果并覆盖整个屏幕。相关代码如下:

import customtkinter as ctk
class Window(ctk.CTk):
  def __init__(self):
    super().__init__()

    self.wm_attributes("-fullscreen", True)
    self.resizable(False, False)
    self.toplevel_window = None
    #(some codes)

w = Window()
w.mainloop()

运行后窗口看似全屏,但无法覆盖整个屏幕。我还尝试了self.state("zoomed")(无效果)和self.attributes("-fullscreen", True)(结果相同)。

解决方法

  • 移除self.resizable(False, False),该设置会干扰全屏模式下的窗口布局计算,导致无法完全覆盖屏幕。
  • 先设置窗口尺寸匹配屏幕实际大小,再启用全屏属性,确保窗口铺满整个屏幕:
    import customtkinter as ctk
    class Window(ctk.CTk):
      def __init__(self):
        super().__init__()
    
        # 获取当前屏幕的宽高
        screen_width = self.winfo_screenwidth()
        screen_height = self.winfo_screenheight()
        # 强制窗口尺寸适配屏幕
        self.geometry(f"{screen_width}x{screen_height}+0+0")
        # 启用全屏模式
        self.attributes("-fullscreen", True)
        
        self.toplevel_window = None
        #(some codes)
    
    w = Window()
    w.mainloop()
    
  • 检查系统任务栏设置:部分系统默认任务栏会保持在窗口上方,可调整任务栏为"自动隐藏"模式,或在系统显示设置中允许窗口覆盖任务栏。
  • 多显示器环境下,若目标是特定显示器,可通过self.winfo_screenwidth()和self.winfo_screenheight()获取对应显示器的尺寸,确保窗口适配正确屏幕。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.08 23:48:21