Python Forum
[WxPython] GridBagSizer - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: [WxPython] GridBagSizer (/thread-33162.html)



GridBagSizer - menator01 - Apr-03-2021

I'm trying place a wx.PaintDC object inside a cell for the GridBagSizer.
I don't understand why it doesn't show.
I can use a Boxsizer and it will show the title. I can place text inside and it will show. Just not with the PaintDC.
Any help would be great.

#! /usr/bin/env python3

# Do the imports
import wx

class Header(wx.Panel):
    def __init__(self, parent, id):
        wx.Panel.__init__(self, parent, id)
        self.Bind(wx.EVT_PAINT, self.OnPaint)

    def OnPaint(self, event):
        font = wx.Font(25, wx.ROMAN, wx.ITALIC, wx.BOLD)
        self.SetBackgroundColour('white')

        dc = wx.PaintDC(self)
        dc.SetFont(font)
        dc.DrawText('wxPython Yahtzee', 250, 10)
        self.SetForegroundColour('orange')


class MainWindow(wx.Frame):
    def __init__(self, parent, id):
        wx.Frame.__init__(self, parent, -1, 'Yahtzee', size=(800, 600))
        sizer = wx.GridBagSizer(vgap=2, hgap=2)
        header = Header(self, wx.ID_ANY)
        sizer.Add(header, pos=(0,0), flag=wx.EXPAND, span=(1, 1))
        self.SetSizerAndFit(sizer)


def main():
    app = wx.App(False)
    window = MainWindow(None, wx.ID_ANY)
    window.Show()
    app.MainLoop()



RE: GridBagSizer - deanhystad - Apr-03-2021

What is the size of your Header?


RE: GridBagSizer - menator01 - Apr-03-2021

Using the font point 25. The window width is 800. Going to center the text with that. I could use the StaticText but, I want to give a shadow effect so, I'm trying with the PaintDC.


RE: GridBagSizer - menator01 - Apr-03-2021

I figured it out from your hint. Just needed to set the size. Thanks. :)