Python 将wx.DrawCircle与框架中心对齐
嗨,我想在画面的中心画一个圆圈。 有没有像wx.Align_Center这样的东西我可以和wx一起使用。DrawCircle下面是我的代码Python 将wx.DrawCircle与框架中心对齐,python,python-2.7,wxpython,wxwidgets,Python,Python 2.7,Wxpython,Wxwidgets,嗨,我想在画面的中心画一个圆圈。 有没有像wx.Align_Center这样的东西我可以和wx一起使用。DrawCircle下面是我的代码 #!/usr/bin/python # points.py import wx import random class Points(wx.Frame): def __init__(self, parent, id, title): wx.Frame.__init__(self, parent, id, title, size=
#!/usr/bin/python
# points.py
import wx
import random
class Points(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, size=(250, 150))
self.Bind(wx.EVT_PAINT, self.OnPaint)
self.Centre()
self.Show(True)
def OnPaint(self, event):
dc = wx.PaintDC(self)
dc.SetBrush(wx.Brush('RED'))
dc.DrawCircle(20,20)
app = wx.App()
Points(None, -1, 'Test')
app.MainLoop()
只需得到框架的大小,然后将宽度和高度除以2
import wx
import random
class Points(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, size=(250, 150))
self.Bind(wx.EVT_PAINT, self.OnPaint)
self.Centre()
self.Show(True)
def OnPaint(self, event):
w, h = self.GetClientSize()
dc = wx.PaintDC(self)
dc.SetBrush(wx.Brush('RED'))
dc.DrawCircle(w/2,h/2, 20)
app = wx.App()
Points(None, -1, 'Test')
app.MainLoop()
那会让你离得很近。您可能需要稍微调整高度,因为我不认为GetSize占系统菜单(所有窗口的顶部栏)的宽度。只需获取框架的大小,然后将宽度和高度除以2即可
import wx
import random
class Points(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, size=(250, 150))
self.Bind(wx.EVT_PAINT, self.OnPaint)
self.Centre()
self.Show(True)
def OnPaint(self, event):
w, h = self.GetClientSize()
dc = wx.PaintDC(self)
dc.SetBrush(wx.Brush('RED'))
dc.DrawCircle(w/2,h/2, 20)
app = wx.App()
Points(None, -1, 'Test')
app.MainLoop()
那会让你离得很近。您可能需要稍微调整高度,因为我不认为GetSize占系统菜单(所有窗口的顶部栏)的宽度。只需获取框架的大小,然后将宽度和高度除以2即可
import wx
import random
class Points(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, size=(250, 150))
self.Bind(wx.EVT_PAINT, self.OnPaint)
self.Centre()
self.Show(True)
def OnPaint(self, event):
w, h = self.GetClientSize()
dc = wx.PaintDC(self)
dc.SetBrush(wx.Brush('RED'))
dc.DrawCircle(w/2,h/2, 20)
app = wx.App()
Points(None, -1, 'Test')
app.MainLoop()
那会让你离得很近。您可能需要稍微调整高度,因为我不认为GetSize占系统菜单(所有窗口的顶部栏)的宽度。只需获取框架的大小,然后将宽度和高度除以2即可
import wx
import random
class Points(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, size=(250, 150))
self.Bind(wx.EVT_PAINT, self.OnPaint)
self.Centre()
self.Show(True)
def OnPaint(self, event):
w, h = self.GetClientSize()
dc = wx.PaintDC(self)
dc.SetBrush(wx.Brush('RED'))
dc.DrawCircle(w/2,h/2, 20)
app = wx.App()
Points(None, -1, 'Test')
app.MainLoop()
那会让你离得很近。您可能需要稍微调整一下高度,因为我不认为GetSize占系统菜单(所有窗口的顶部栏)的宽度。GetClientSize将排除框架客户端区域之外的部分,如标题栏和边框。GetClientSize将排除框架客户端区域之外的部分,与标题栏和边框类似。GetClientSize将排除框架客户端区域之外的部分,与标题栏和边框类似。GetClientSize将排除框架客户端区域之外的部分,与标题栏和边框一样。