wxPython - 没有绘画事件的绘图 [英] wxPython - drawing without paint event

查看:65
本文介绍了wxPython - 没有绘画事件的绘图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个wxPython程序,无论是否发生绘制事件,都需要定期在

上绘制DC。我知道如何使用
让ClientDC进行绘图,我知道绘图调用

make。但是我该怎么做呢?在我调用MainLoop之后,除非有事件,否则我的代码都不会被调用。没有事件,

所以我的代码没有被调用。我该怎么办?

解决方案

8月9日晚上7:46,Matt Bitten< mbitte ... @ yahoo。 comwrote:


我有一个wxPython程序,需要在定期的

上对DC进行绘图...没有事件,

所以我的代码没有被调用。我该怎么办?



然后事件是:定期,即时间的流逝。

你可以使用wx.Timer定期创建活动,你的代码可以回复:

-------

import wx


class MyFrame(wx.Frame):

def __init __(self):

wx.Frame .__ init __(self ,无,-1,我的窗口)


panel = wx.Panel(self,-1)

self.text = wx.StaticText (panel,-1," hello",pos =(40,40))


self.timer = wx.Timer(self)

self .Bind(wx.EVT_TIMER,self.on_timer_event)

self.timer.Start(毫秒= 1000,oneShot = False)


def on_timer_event(self,事件):

if self.text.GetLabel()==" hello":

self.text.SetLabel(" goodbye")

else:

self.text.SetLabel(" hello")

app = wx.App(redirect = False)


win = MyFrame( )

win.Show()


app.MainLoop()

----------- -----


确保将计时器保存在自己的位置,以便对对象有永久的

引用,否则计时器将被销毁当

__init_返回时。



8月10日凌晨1点40分,7stud< bbxx789_0 .. 。@ yahoo.comwrote:


8月9日晚上7:46,Matt Bitten< mbitte ... @ yahoo.comwrote:


我有一个wxPython程序,需要在定期的

上对DC进行绘图....而且没有事件,

所以我的代码没有被调用。我该怎么办?



然后事件是:定期,即时间的推移。

你可以使用wx.Timer定期创建活动,

您的代码可以回复:

...



谢谢!


在一个相关的主题上,看起来好像做*全部*绘图



回复油漆事件。当我从计时器中得到一个事件时,我会告诉wx窗口的一部分需要重绘,并依赖它

给我一个画画,即使什么都没有更高优先级需要

完成。

我已经看到了其他GUI内容中推荐的这种逻辑。在wxPython中它是一个好主意吗?如果是的话,怎么做呢?


gl ************ @ gmail.com 写道:
< blockquote class =post_quotes>
在一个相关的主题上,似乎很高兴做* all *

绘图

回应绘制事件。当我从计时器中获得一个事件时,我会告诉wx窗口的一部分需要重绘,并且

依靠它来给我一个画画,即使什么都没有需要优先考虑
优先级。

我已经在其他GUI浏览器中看到过这种逻辑推荐。

在wxPython中是一个好主意,如果是这样,那怎么做呢?



至少不需要 - 在装置事件内外都有设备上下文使用




一个很好的策略来自wxPython in Action中的一个例子。是

以下:


*框架具有绘制到BufferedDC的Draw方法,这是
链接到位图会员


*在paint方法中,位图成员被绘制到屏幕上


问候,

Bj?


-

BOFH借口#393:


来自范艾伦腰带的干扰。


I''ve got a wxPython program that needs to do some drawing on a DC on a
regular basis, whether or not a paint event happens. I know how to
make a ClientDC to do the drawing in, and I know what drawing calls to
make. But how do I make it all happen? After I call MainLoop, none of
my code gets called unless there is an event. And there is no event,
so my code doesn''t get called. What do I do?

解决方案

On Aug 9, 7:46 pm, Matt Bitten <mbitte...@yahoo.comwrote:

I''ve got a wxPython program that needs to do some drawing on a DC on a
regular basis.... And there is no event,
so my code doesn''t get called. What do I do?

Then the event is: "on a regular basis", i.e. the passage of time.
You can use a wx.Timer to create events at regular intervals, which
your code can respond to:

-------
import wx

class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, "My Window")

panel = wx.Panel(self, -1)
self.text = wx.StaticText(panel, -1, "hello", pos=(40, 40) )

self.timer = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.on_timer_event)
self.timer.Start(milliseconds=1000, oneShot=False)

def on_timer_event(self, event):
if self.text.GetLabel() == "hello":
self.text.SetLabel("goodbye")
else:
self.text.SetLabel("hello")
app = wx.App(redirect=False)

win = MyFrame()
win.Show()

app.MainLoop()
----------------

Make sure you save the timer in self so that you have a permanent
reference to the object, otherwise the timer will be destroyed when
__init_ returns.



On Aug 10, 1:40 am, 7stud <bbxx789_0...@yahoo.comwrote:

On Aug 9, 7:46 pm, Matt Bitten <mbitte...@yahoo.comwrote:

I''ve got a wxPython program that needs to do some drawing on a DC on a
regular basis.... And there is no event,
so my code doesn''t get called. What do I do?


Then the event is: "on a regular basis", i.e. the passage of time.
You can use a wx.Timer to create events at regular intervals, which
your code can respond to:
...

Thanks!

On a related topic, it seems like it would be nice to do *all* drawing
in
response to paint events. When I get an event from the timer, I would
just tell wx that part of the window needs redrawing, and depend on it
to give me a paint even when nothing of higher priority needs to be
done.
I''ve seen this kind of logic recommended in other GUI tookits. Is it a
good idea in wxPython, and, if so, how does one do it?


gl************@gmail.com wrote:

On a related topic, it seems like it would be nice to do *all*
drawing in
response to paint events. When I get an event from the timer, I
would just tell wx that part of the window needs redrawing, and
depend on it to give me a paint even when nothing of higher
priority needs to be done.
I''ve seen this kind of logic recommended in other GUI tookits. Is
it a good idea in wxPython, and, if so, how does one do it?

At least it is not required -- there are device contexts for use
inside and outside of paint events.

One nice strategy from an example in "wxPython in Action" is the
following:

* the frame has Draw methods that draw into a BufferedDC, which is
chained to a bitmap member

* inside the paint method, the bitmap member is drawn to screen

Regards,
Bj?rn

--
BOFH excuse #393:

Interference from the Van Allen Belt.


这篇关于wxPython - 没有绘画事件的绘图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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