矩形不会出现在 wxpython 上 [英] rectangle wont show up on wxpython

查看:36
本文介绍了矩形不会出现在 wxpython 上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Windows 计算机上不会显示矩形.我把这个给了 mac 用户的其他人,矩形出现了.我没有收到任何错误,所以我似乎无法弄清楚.我正在使用 python 2.7.7.

The rectangle won't show up for me on a windows computer. I gave this to someone else who was a mac user and the rectangle showed up. I am not receiving any errors so I can't seem to figure this out. I am using python 2.7.7.

import socket
import wx

class WindowFrame(wx.Frame):
    def __init__(self, parent, title):
        wx.Frame.__init__(self, parent, title = title, size=(500, 400))
        self.panel=wx.Panel(self)
        self.panel.SetBackgroundColour("#E6E6E6")
        self.control = wx.TextCtrl(self.panel, style = wx.TE_MULTILINE, size =(410, 28), pos=(0,329))

        sendbutton=wx.Button(self.panel, label ="Send", pos =(414,325), size=(65,35))
        self.panel.Bind(wx.EVT_PAINT, self.OnPaint)

        self.Centre()
        self.Show()


    def OnPaint(self, event):
        dc = wx.PaintDC(self)
        dc.SetPen(wx.Pen('#d4d4d4'))
        dc.SetBrush(wx.Brush('#c56c00'))
        dc.DrawRectangle(10, 15, 90, 60)
        self.Show(True)
if __name__=="__main__": 
    app = wx.App(False)
    frame = WindowFrame(None, 'ChatClient')
    app.MainLoop()

推荐答案

此代码的问题在于 OP 想要在面板上绘制,但随后继续告诉 PaintDC 对象绘制到框架上.OnPaint 方法应如下所示:

The problem with this code is that the OP is wanting to draw on the panel, but then proceeds to tell the PaintDC object to paint to the frame. The OnPaint method should look like this:

def OnPaint(self, event):
    dc = wx.PaintDC(self.panel)  # <<< This was changed
    dc.SetPen(wx.Pen('#d4d4d4'))
    dc.SetBrush(wx.Brush('#c56c00'))
    dc.DrawRectangle(10, 15, 90, 60)

这篇关于矩形不会出现在 wxpython 上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆