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

从wx.TextCtrl复制文本后调用ImageGrab.grabclipboard()致程序挂起

从wx.TextCtrl复制文本后,ImageGrab.grabclipboard()导致程序挂起

问题详情

当从wx.TextCtrl复制文本到剪贴板后,调用ImageGrab.grabclipboard()读取剪贴板中的图像时,程序会出现挂起情况。但如果是从程序外部复制文本到剪贴板,点击按钮则能正常输出“No image found on clipboard”。

环境配置

  • Ubuntu 20.04
  • Python 3.9
  • Pillow 9.5.0(最初发现问题),升级至10.0.0后问题仍未解决

最小复现代码

import wx
from PIL import ImageGrab

class MyFrame(wx.Frame):
    def __init__(self, parent):
        super().__init__(parent, title="My Frame")

        self.text_ctrl = wx.TextCtrl(self)
        self.button = wx.Button(self, label="Grab image")

        self.button.Bind(wx.EVT_BUTTON, self.on_click)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.text_ctrl, 1, wx.EXPAND)
        sizer.Add(self.button, 0, wx.ALIGN_CENTER)

        self.SetSizer(sizer)
        self.Show()

    def on_click(self, event):
        try:
            img = ImageGrab.grabclipboard()
            print('Image grabbed from clipboard')
        except:
            print('No image found on clipboard')

app = wx.App()
MyFrame(None)
app.MainLoop()

触发步骤

  1. 在wx.TextCtrl中输入文本,选中并复制到剪贴板
  2. 点击“Grab image”按钮,程序随即挂起

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.13 22:15:06