我想绘制一个以wx.EmptyBitmap为中心的数字.
我怎么能用wxpython做到这一点?
提前致谢 :)
import wx
app = None
class Size(wx.Frame):
def __init__(self, parent, id, title):
frame = wx.Frame.__init__(self, parent, id, title, size=(250, 200))
bmp = wx.EmptyBitmap(100, 100)
dc = wx.MemoryDC()
dc.SelectObject(bmp)
dc.DrawText("whatever", 50, 50)
dc.SelectObject(wx.NullBitmap)
wx.StaticBitmap(self, -1, bmp)
self.Show(True)
app = wx.App()
Size(None, -1, 'Size')
app.MainLoop()
Run Code Online (Sandbox Code Playgroud)
这段代码只给我一个黑色图像,我做错了什么?这里缺少什么..
在wx.MemoryDC中选择bmp,在该dc上绘制任何内容,然后选择该位图,例如
import wx
app = None
class Size(wx.Frame):
def __init__(self, parent, id, title):
frame = wx.Frame.__init__(self, parent, id, title, size=(250, 200))
w, h = 100, 100
bmp = wx.EmptyBitmap(w, h)
dc = wx.MemoryDC()
dc.SelectObject(bmp)
dc.Clear()
text = "whatever"
tw, th = dc.GetTextExtent(text)
dc.DrawText(text, (w-tw)/2, (h-th)/2)
dc.SelectObject(wx.NullBitmap)
wx.StaticBitmap(self, -1, bmp)
self.Show(True)
app = wx.App()
app.MainLoop()
Run Code Online (Sandbox Code Playgroud)