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 (i.e., 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,开发者_如何学JAVA 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()
精彩评论