简体   繁体   中英

How can I get a wxPython frame with FancyText and no border (wx.BORDER_NONE)?

I would like to build a wxPython window without borders (ie, style = wx.BORDER_NONE ) and use fancytext ( wx.lib.fancytext ) inside this window. Note that I am very new to wxPython and my question may sound stupid. (this is actually my first attempt of using wxPython).

I figured that I will need to use a panel in my frame when using fancytext as one needs the OnPaint method for setting the fanciness for the text. However, it seems to be impossible to use panels (or even sizers ) with style = wx.BORDER_NONE .

This is what I would like, but without the window borders and stuff:

import  wx
import  wx.lib.fancytext as fancytext

test_str2 = '<font family="swiss" color="dark green" size="40">big green text</font>'

class FancyText(wx.Panel):
    """display fancytext on a panel"""
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, wx.ID_ANY)
        self.Bind(wx.EVT_PAINT, self.OnPaint)

    def OnPaint(self, evt):
        """generate the fancytext on a paint dc canvas"""
        dc = wx.PaintDC(self)
        fancytext.RenderToDC(test_str2, dc, 0, 20)


app = wx.App(0)
frame = wx.Frame(None, wx.ID_ANY, title='wxPython fancy text', size=(500, 250))
frame.Centre()
FancyText(frame)
frame.Show(True)
app.MainLoop()

(This examples uses code found here and from the wxPython demo)

If one changes the line initializing the window to

frame = wx.Frame(None, wx.ID_ANY, title='wxPython fancy text', size=(500, 250), style = wx.BORDER_NONE)

the fancytext disappears.

Is there any way I can use fancytext on a window without borders ( style = wx.BORDER_NONE )?

The problem is that the panel is not resizing to the size of the frame. You need to use a sizer, like this:

sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(FancyText(frame), 1, wx.EXPAND)
frame.SetSizer(sizer)
frame.Layout()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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