在 wxPython 中使用 time.sleep [英] using time.sleep in wxPython

查看:56
本文介绍了在 wxPython 中使用 time.sleep的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在重新定位位图按钮后在我的 wxPython 代码中使用 time.sleep 导致我的按钮完全空白.按钮应该在的区域只剩下一个空白区域.任何人都可以解释原因并提出任何解决方案吗?这是我的代码:

Using time.sleep in my wxPython code just after re-positioning a bitmapbutton caused my button to go totally blank. Just a white space was left in the region where the button should have been. Can any one please explain the reason and suggest any solution? Here's my code:

import wx
import time
class gui(wx.Frame):
  def __init__(self,parent,id):
    wx.Frame.__init__(self,parent,id,'New Window',pos=(0,0),size=wx.DisplaySize())
    panel=wx.Panel(self)
    self.SetBackGroundColour('green')
    self.pic=wx.BitmapButton(self,-1,wx.Image("Candle.jpg",wx.BITMAP_TYPE_ANY).ConvertToBitmap(),pos=(700,300))
    self.Bind(wx.EVT_BUTTON,self.position,self.pic)
  def positon(self,event):
    self.pic.Hide()
    self.pic=wx.BitmapButton(self,-1,wx.Image("Candle.jpg",wx.BITMAP_TYPE_ANY).ConvertToBitmap(),pos=(700,300))
    time.sleep(2)
    self.pic.Hide()
if __name__=='__main__':
  app=wx.PySimpleApp()
  frame=gui(None,-1)
  frame.Show()
  app.MainLoop()

推荐答案

time.sleep() 阻塞 wx 的主循环并使 GUI 在您告诉它休眠的时间段内无响应.有几种选择.您可以使用 wx.Timer 或使用 线程(或类似的).不过,我认为在您的用例中使用 Timer 更有意义.

time.sleep() blocks wx's mainloop and makes the GUI unresponsive for however long you've told it to sleep. There are several alternatives. You can use a wx.Timer or use threads (or similar). I think using a Timer makes more sense in your use case though.

这篇关于在 wxPython 中使用 time.sleep的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆