简体   繁体   English

为什么我的window的客户区什么都没有绘制 - wxpython

[英]Why will nothing be drawn on my client area of the window - wxpython

I am trying to draw a simple line on the client area of a frame.我想在框架的客户区画一条简单的线。 I can't figure out why nothing will draw.我不明白为什么什么都不会画。 I usually use Pygame for this stuff.对于这些东西,我通常使用 Pygame。

Here is my code:这是我的代码:

import wx
sigwin = wx.Frame(None,title = "Name of Window")
sigwin.SetSize(-1,-1,600,200))
sigwin.SetBackgroundColour((255,255,255))
txt = wx.StaticText(sigwin, id=-1, label='Please sign your name in the box below:',pos=(20,40),style=wx.ALIGN_CENTRE_HORIZONTAL)
font3 = wx.Font(15, wx.DECORATIVE, wx.NORMAL, wx.NORMAL,0,'Comic Sans MS')
txt.SetFont(font3)
sigwin.Centre()

def on_paint(event):
    dc = wx.ClientDC(event.GetEventObject())
    dc.Clear()
    dc.SetPen(wx.Pen("BLACK", 0))
    dc.DrawLine(0, 0, 500, 500)
    
sigwin.Bind(wx.EVT_PAINT, on_paint)
sigwin.Show()

Since you're using a GUI library, it's processing the paint event after you do.由于您使用的是 GUI 库,它会在您完成后处理绘画事件。 In this case, you're drawing a line then wx is drawing the text box on top.在这种情况下,您正在绘制一条线,然后 wx 在顶部绘制文本框。

This code removes the text box and shows your line:此代码删除文本框并显示您的行:

import wx
app = wx.App(False)

sigwin = wx.Frame(None,title = "Name of Window")
sigwin.SetSize(-1,-1,600,200)
sigwin.SetBackgroundColour((255,255,255))
#txt = wx.StaticText(sigwin, id=-1, label='Please sign your name in the box below:',pos=(20,40),style=wx.ALIGN_CENTRE_HORIZONTAL)
#font3 = wx.Font(15, wx.DECORATIVE, wx.NORMAL, wx.NORMAL,0,'Comic Sans MS')
#txt.SetFont(font3)
sigwin.Centre()

def on_paint(event):
    dc = wx.ClientDC(event.GetEventObject())
    dc.Clear()
    dc.SetPen(wx.Pen("BLACK", 0))
    dc.DrawLine(0, 0, 500, 500)
    print('paint')
    
sigwin.Bind(wx.EVT_PAINT, on_paint)
sigwin.Show()

#frame = sigwin(None, "Sample editor")
app.MainLoop()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM