Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将wx.DrawCircle与框架中心对齐_Python_Python 2.7_Wxpython_Wxwidgets - Fatal编程技术网

Python 将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=

嗨,我想在画面的中心画一个圆圈。 有没有像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=(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将排除框架客户端区域之外的部分,与标题栏和边框一样。