Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6694513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:06:37+00:00 2026-05-26T06:06:37+00:00

I’m trying to create a basic date-selector/calendar in wxPython. So far I’ve managed to

  • 0

I’m trying to create a basic date-selector/calendar in wxPython. So far I’ve managed
to add all the necessary widgets to my grid, but I’m struggling to get them
positioned properly. Although there are numerous things I don’t fully understand,
I’m getting particularly frustrated with the wx.SpinCtrl widget, which seems to be
surrounded by a massive border despite the fact that none is specified. Can anyone
tell me how to remove this? I want the spin control to be just a couple of pixels
away from the top of the frame, with the text ‘February’ the same number of pixels away
from the bottom of the control. I’ve tried all manner of approaches but none seem to
have any effect.

import wx
import calendar

MONTH_NAME_AS_KEY = {"January":1, "February":2, "March":3, "April":4, "May":5, "June":6,
                 "July":7, "August":8, "September":9, "October":10, "November":11,
                 "December":12}

def getMonthNumber(nameAsString):
    return MONTH_NAME_AS_KEY.get(nameAsString)


class Example(wx.Frame):

    def __init__(self, parent, title): 
        super(Example, self).__init__(parent, title=title,size=(300, 350))

        self.InitUI() 
        self.Centre() 
        self.Show()

    def InitUI(self):

        self.panel = wx.Panel(self)

        mainSizer = wx.BoxSizer(wx.VERTICAL)

        fgs = wx.FlexGridSizer(rows=2, cols=2)

        # fgs 1: blank space
        filler = wx.StaticText(self.panel, -1, label="")
        fgs.Add(filler)

        # fgs 2: creating containers
        vSizer = wx.BoxSizer(wx.VERTICAL)
        yearNavigationBox = wx.BoxSizer(wx.HORIZONTAL)
        monthNavigationBox = wx.BoxSizer(wx.HORIZONTAL)

        # year navigation
        sc = wx.SpinCtrl(self.panel,-1, "", size=(70,70))
        sc.SetRange(1980,2060)
        sc.SetValue(2011)

        yearNavigationBox.Add(sc, wx.ALL, wx.EXPAND|wx.TOP)

        # month navigation
        monthDown = wx.StaticText(self.panel, -1, label="<")    
        monthUp = wx.StaticText(self.panel, -1, label=">")      


        monthName = wx.StaticText(self.panel, wx.ID_ANY, label="February")  

        monthNavigationBox.Add(monthDown)
        monthNavigationBox.Add(monthName)
        monthNavigationBox.Add(monthUp)

        vSizer.Add(yearNavigationBox)
        vSizer.Add(monthNavigationBox)

        fgs.Add(vSizer)

        # fgs 3: the date of the month writ large
        date = wx.StaticText(self.panel, wx.ID_ANY, label='31', style=wx.ALIGN_CENTER)
        dateFont = wx.Font(150, wx.DEFAULT, wx.NORMAL, wx.BOLD)
        date.SetFont(dateFont)

        fgs.Add(date)


        # fgs 4: the date grid
        dateSquareSizer = wx.GridSizer(rows=6, cols=7, hgap=1, vgap=6)

        dayFont = wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD)
        days = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
        for item in days:
            day = wx.StaticText(self.panel, wx.ID_ANY, label=item)
            day.SetFont(dayFont)
            dateSquareSizer.Add(day)    

        y = 2012
        m = getMonthNumber(monthName.GetLabel())    

        gridData = list(calendar.Calendar().itermonthdays(y, m))
        while len(gridData)<43: gridData.append(0)

        for i in gridData:
            if i == 0: i=""
            square = wx.StaticText(self.panel, wx.ID_ANY, label=str(i))
            square.SetFont(dayFont)
            dateSquareSizer.Add(square, wx.ID_ANY)      

        fgs.Add(dateSquareSizer)

        mainSizer.Add(fgs, wx.ALL, 2)

        self.panel.SetSizer(mainSizer)
        mainSizer.Fit(self)



if __name__ == '__main__':

    app = wx.App() 
    Example(None, title='') 
    app.MainLoop()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:06:38+00:00Added an answer on May 26, 2026 at 6:06 am

    It looks like you don’t quite have the sizer’s Add signature correct. It should be sizer.Add(widget, proportion, flags, border)

    You keep skipping the proportion and are not specifying a border at all. If you did this instead:

    yearNavigationBox.Add(sc, 0, wx.EXPAND|wx.TOP, 5)
    

    It will put the spinner 5 pixels below the top of the frame (or whatever widget is added before this one). You have a few other places where you’re skipping the proportion flag and putting other random stuff in its place. You’ll want to go through and change that. Here are a couple tutorials:

    • http://www.blog.pythonlibrary.org/2008/05/18/a-wxpython-sizers-tutorial/
    • http://wiki.wxpython.org/UsingSizers
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to loop through a bunch of documents I have to put
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.