Python Forum
[WxPython] GridBagSizer
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[WxPython] GridBagSizer
#1
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()
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#2
What is the size of your Header?
menator01 likes this post
Reply
#3
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.
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#4
I figured it out from your hint. Just needed to set the size. Thanks. :)
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020