gpt4 book ai didi

python - wxPython - 使用 DC 绘制一个未填充的矩形

转载 作者:太空宇宙 更新时间:2023-11-03 23:50:07 25 4
gpt4 key购买 nike

dc.SetPen(wx.Pen(wx.BLACK, 0))
dc.SetBrush(wx.Brush("C0C0C0"))
dc.DrawRectangle(50,50,50,50)

这是我绘制 50x50 灰色无边框框的最佳尝试。但是,将笔宽设置为 0 似乎没有任何作用,设置画笔只是将填充从纯白色更改为纯黑色。

这是在面板的上下文中,以防它是问题的一部分:

class DrawRect(wx.Panel):
def __init__(self,parent=None,id=-1,pos=(-1,-1),size=(-1,-1),style=0):
wx.Panel.__init__(self,parent,id,size,pos,style)
self.SetBackgroundColour("#D18B47")
self.Bind(wx.EVT_PAINT,self.onPaint)

def onPaint(self, event):
event.Skip()
dc = wx.PaintDC(event.GetEventObject())
self.drawRect(dc)

def drawRect(self,dc):
dc.SetPen(wx.Pen("FFCE8A", 0))
dc.SetBrush(wx.Brush("C0C0C0"))
dc.DrawRectangle(50,50,50,50)

最佳答案

这是一个灰色的矩形:

import wx

class MyPanel(wx.Panel):
""" class MyPanel creates a panel to draw on, inherits wx.Panel """
def __init__(self, parent, id):
# create a panel
wx.Panel.__init__(self, parent, id)
self.SetBackgroundColour("white")
self.Bind(wx.EVT_PAINT, self.OnPaint)

def OnPaint(self, evt):
"""set up the device context (DC) for painting"""
self.dc = wx.PaintDC(self)
self.dc.BeginDrawing()
self.dc.SetPen(wx.Pen("grey",style=wx.TRANSPARENT))
self.dc.SetBrush(wx.Brush("grey", wx.SOLID))
# set x, y, w, h for rectangle
self.dc.DrawRectangle(250,250,50, 50)
self.dc.EndDrawing()
del self.dc

app = wx.PySimpleApp()
# create a window/frame, no parent, -1 is default ID
frame = wx.Frame(None, -1, "Drawing A Rectangle...", size = (500, 500))
# call the derived class, -1 is default ID
MyPanel(frame,-1)
# show the frame
frame.Show(True)
# start the event loop
app.MainLoop()

关于python - wxPython - 使用 DC 绘制一个未填充的矩形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2256722/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com