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

Ubuntu系统下PYSimpleGUI许可证窗口无法显示,求解决方案

问题:Ubuntu下PySimpleGUI许可证窗口无法显示,仅显示托盘图标

运行以下示例代码时(终端执行python PYGtest.py):

import PySimpleGUI as sg
layout = [ [sg.Text('Hello, world!')] ]
window = sg.Window('Hello Example', layout)
while True:
    event, values = window.read()
    if event == sg.WIN_CLOSED:
        break
window.close()

在Ubuntu系统中,许可证窗口无法正常显示,仅左侧托盘出现图标,右键点击图标可关闭。本人持有开发者密钥,需要用到该许可证窗口。

已安装的依赖版本:

  • rsa 4.9
  • python 3.12.2
  • tk 8.6.14
  • pysimplegui 5.0.4

尝试过不同示例代码,问题一致,许可证窗口始终无法显示,求解决方法。


解决建议

1. 强制指定窗口显示位置

PySimpleGUI在Ubuntu下可能存在窗口位置偏移问题,创建sg.Window时显式设置位置,比如强制居中:

screen_width, screen_height = sg.Window.get_screen_size()
window_x = (screen_width - 300) // 2
window_y = (screen_height - 200) // 2
window = sg.Window('Hello Example', layout, location=(window_x, window_y))

2. 切换到Xorg会话

Ubuntu默认的Wayland会话可能限制托盘应用的窗口显示,登录时点击用户名旁的齿轮图标,选择「Ubuntu on Xorg」,重启后测试。

3. 降级PySimpleGUI版本

PySimpleGUI 5.x与Python3.12的Ubuntu环境可能存在兼容性问题,尝试降级到稳定的4.x版本:

pip uninstall pysimplegui -y
pip install pysimplegui==4.60.5

4. 排查Tkinter基础功能

先验证Tkinter本身是否正常,运行以下代码:

import tkinter as tk
root = tk.Tk()
root.title("Tkinter Test")
tk.Label(root, text="Hello Tkinter").pack()
root.mainloop()

若窗口仍无法显示,重新安装Tkinter:

sudo apt-get install python3-tk

5. 启用调试模式定位问题

添加调试参数查看窗口初始化日志:

window = sg.Window('Hello Example', layout, debug=True)

查看终端输出的日志,寻找窗口显示相关的错误提示。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.18 08:30:59