ans*_*410 8 python multithreading wxpython animated-gif
我正在尝试读取一些图像(后来打算对它们执行某些任务),并且正在将图像读入内存.我想显示一个动画的'.gif'图片.为此我不得不使用Threads.现在它给出错误:
python: Fatal IO error 11 (Resource temporarily unavailable) on X server :0.0.
Run Code Online (Sandbox Code Playgroud)
有时它会给出错误:
python: Fatal IO error 0 (Success) on X server :0.0.
Run Code Online (Sandbox Code Playgroud)
(是错误消息几乎交替更改)我不知道为什么会发生此错误以及如何删除它.
import wx
from wx import animate
import thread
import os
class AniGif(wx.Dialog):
def __init__(self, parent, id, title):
wx.Dialog.__init__(self, parent, id, title, size=(300, 300))
buttonOk = wx.Button(self, id=3, label="Ok", pos=(75, 50), size=(50, 50))
self.Bind(wx.EVT_BUTTON, self.OnClick, id=3)
def OnClick(self, event) :
clock = "loading.gif"
showclock = wx.animate.GIFAnimationCtrl(self, -1, clock)
showclock.Play()
thread.start_new_thread(grabImages, ( ))
def grabImages():
global dirim
dirim = {}
path = './images/soccer/'
listing = os.listdir(path)
for infile in listing:
if len(infile)>4 and infile[-4:]=='.jpg' :
print path+infile
dirim[infile]=wx.Bitmap(path+infile)
app = wx.App()
dia = AniGif(None, -1, "Ani Gif")
dia.ShowModal()
dia.Destroy()
app.MainLoop()
Run Code Online (Sandbox Code Playgroud)
如果我更换这条线
dirim[infile]=wx.Bitmap(path+infile)
Run Code Online (Sandbox Code Playgroud)
用虚线:
dirim[infile]=infile
Run Code Online (Sandbox Code Playgroud)
它工作正常,没有错误.
如果我更换这条线
thread.start_new_thread(grabImages, ( ))
Run Code Online (Sandbox Code Playgroud)
用这样的东西:
grabImages()
Run Code Online (Sandbox Code Playgroud)
它工作正常,没有错误.唯一的问题我无法显示动画gif然后..
我试图删除〜/ .gconf中/桌面/ GNOME /外围设备如提到的链接通过给华金.它不起作用..我也试过'xhost +'.我从网上的某个地方找到了.仍然没有成功.
请告诉我们这段代码中发生了什么..并建议我使用ubuntu 10.04操作系统的解决方案.目录权限是:
drwxr-xr-x images
drwxr-xr-x soccer
Run Code Online (Sandbox Code Playgroud)
Python verion的细节是:关于linux2的Python 2.6.5(r265:79063,2010年4月16日,13:09:56)[GCC 4.4.3]
当图像位于脚本目录中时(我使用自己的动画 gif 和 png),您的代码在 win7 中非常适合我,使用 wxpython 2.8.12.1 和 python 2.6.7 在 Spe 版本 0.8.4.i 上运行。
from wx import animate我唯一需要的改变是除了 wx 之外还导入 animate ( ) 并使用
showclock = animate.GIFAnimationCtrl(self, -1, clock)
Run Code Online (Sandbox Code Playgroud)
代替
showclock = wx.animate.GIFAnimationCtrl(self, -1, clock)
Run Code Online (Sandbox Code Playgroud)
编辑:有几种情况下,人们会出现与您相同的错误消息,例如此处、此处和此处。最后一个让我认为它可能与 Linux 中 GUI 框架的线程使用有关(另请参阅此处相关内容)。您应该用谷歌搜索错误字符串,看看是否可以获得更多信息,或者以错误字符串为主题提出有关 SO 的特定问题。呃!已经有一个了!
| 归档时间: |
|
| 查看次数: |
8578 次 |
| 最近记录: |