如何用wxpython直接在屏幕上绘图?
我使用的是 Linux 和 e17,并且禁用了合成,我想创建一个能够直接在屏幕上绘制简单几何形状和文本的程序。
我的第一个想法是:
import wx
app = wx.App(False)
s = wx.ScreenDC()
s.Pen = wx.Pen("#FF0000")
s.DrawRectangle(60,60,120,120)
但这行不通,所以我将最后一行替换为:
for i in range(0,129):
s.DrawRectangle(60,60,120,120)
这在某种程度上使它起作用,但这是一个黑客解决方案,要绘制线条,我需要更多地增加迭代量。
我认为问题可能出在透明度上,但不知道如何解决。
任何帮助将不胜感激,谢谢。
I'm using Linux and e17 with composition disabled, and I would like to create a program capable of drawing simple geometrical shapes and text directly onto the screen.
My first thought was to do:
import wx
app = wx.App(False)
s = wx.ScreenDC()
s.Pen = wx.Pen("#FF0000")
s.DrawRectangle(60,60,120,120)
But this wouldn't work, so I replaced the last line with:
for i in range(0,129):
s.DrawRectangle(60,60,120,120)
Which somehow made it work, but it's a hacky solution and to draw lines I need to increase amount of iterations even more.
I think the problem might be with transparency, but have no idea how to solve it.
Any help would be appreciated, thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否在任何地方指定
StartDrawingOnTop
?否则,您可能会遇到透明度问题,因此您可以尝试明确设置。Do you specify,
StartDrawingOnTop
anywhere? Otherwise, it seems you might have a transparency issue so you might try setting that explicitly.我认为您可以通过创建框架和面板然后调用框架的 SetTransparency 方法来设置它来做到这一点。您肯定想使用 DC 或类似 FloatCanvas 之类的东西来进行绘图。无论如何值得一试。
I would think you could do this by creating a frame and panel and then call the frame's SetTransparency method to set that. You definitely want to use DCs or something similar like FloatCanvas to do the drawing. Worth a try anyway.