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 7026531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:07:48+00:00 2026-05-28T00:07:48+00:00

I am pretty new to wxPython, so I generate GUI with wxFormBuilder and try

  • 0

I am pretty new to wxPython, so I generate GUI with wxFormBuilder and try to get extension from some folder and to create checkbox with these exts, but I got

NameError: global name ‘bSizer_Ext’ is not defined

Any suggestion will be appreciated. Thank you.

# -*- coding: utf-8 -*- 

###########################################################################
## Python code generated with wxFormBuilder (version Jun 30 2011)
## http://www.wxformbuilder.org/
##
## PLEASE DO "NOT" EDIT THIS FILE!
###########################################################################

import wx
import os

###########################################################################
## Class Test
###########################################################################

class Test ( wx.Frame ):
    extensions=[]
    def __init__( self, parent ):
        wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = u"Test", pos = wx.DefaultPosition, size = wx.Size( 600,300 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )

        self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )

        bSizer1 = wx.BoxSizer( wx.VERTICAL )

        fg_DirSizer = wx.FlexGridSizer( 0, 2, 0, 2 )
        fg_DirSizer.AddGrowableCol( 1 )
        fg_DirSizer.SetFlexibleDirection( wx.BOTH )
        fg_DirSizer.SetNonFlexibleGrowMode( wx.FLEX_GROWMODE_SPECIFIED )

        self.m_staticText_root = wx.StaticText( self, wx.ID_ANY, u"Root Directory", wx.DefaultPosition, wx.DefaultSize, 0 )
        self.m_staticText_root.Wrap( -1 )
        fg_DirSizer.Add( self.m_staticText_root, 0, wx.ALL, 5 )

        self.root_dir_pick = wx.DirPickerCtrl( self, wx.ID_ANY, wx.EmptyString, u"Select root folder", wx.DefaultPosition, wx.DefaultSize, wx.DIRP_DEFAULT_STYLE|wx.DIRP_DIR_MUST_EXIST|wx.TAB_TRAVERSAL )
        self.root_dir_pick.SetMinSize( wx.Size( 450,25 ) )

        fg_DirSizer.Add( self.root_dir_pick, 0, wx.ALL, 5 )

        bSizer1.Add( fg_DirSizer, 0, wx.EXPAND, 5 )

        bSizer_Ext = wx.BoxSizer( wx.VERTICAL )

        bSizer1.Add( bSizer_Ext, 1, wx.EXPAND, 5 )

        self.SetSizer( bSizer1 )
        self.Layout()

        self.Centre( wx.BOTH )
        self.Show(True)

        # Connect Events
        self.root_dir_pick.Bind( wx.EVT_DIRPICKER_CHANGED, self._ScanRoot )

    def __del__( self ):
        pass


    # Virtual event handlers, overide them in your derived class
    def _ScanRoot( self, event ):
        ext=''
        for root,dirs,files in os.walk(self.root_dir_pick.GetPath()):
            for f in files:
                try:
                    ext = os.path.splitext(f)
                    self.extensions.index(ext[1])
                except:
                    self.extensions.append(ext[1])
        for ext1 in self.extensions:
            chb=wx.CheckBox( bSizer_Ext, wx.ID_ANY, ext1, wx.DefaultPosition, wx.DefaultSize, 0 )


if __name__ == "__main__":
    app = wx.App()
    frame = Test(None)
    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-28T00:07:48+00:00Added an answer on May 28, 2026 at 12:07 am

    Modify the last for loop in _ScanRoot as shown:

    for ext1 in self.extensions:
        chb = wx.CheckBox(self, wx.ID_ANY, ext1, wx.DefaultPosition, wx.DefaultSize, 0 )
        self.bSizer_Ext.Add(chb)
    self.Layout()
    

    Also modify in the program all instances of bSizer_Ext with self.bSizer_Ext

    This code is no functional yet. You need to:

    • Bind your checkboxes to an event in order to detect clicks
    • Keep each checkbox object available to modify them if needed (this is actually optional)

    For example, this is an alternative:

        def OnCheck(self, evt):
            """Here I will decide which actions to take"""
            obj = evt.GetEventObject()
            if obj.IsChecked():
                print "%s selected" % obj.Label
            else:
                print "%s deselected" % obj.Label
    
        # Virtual event handlers, overide them in your derived class
        def _ScanRoot( self, event ):
            ext = ''
            for root, dirs, files in os.walk(self.root_dir_pick.GetPath()):
                for f in files:
                    try:
                        ext = os.path.splitext(f)
                        self.extensions.index(ext[1])
                    except:
                        self.extensions.append(ext[1])
            for ext1 in self.extensions:
                chb = wx.CheckBox(self, wx.ID_ANY, ext1, wx.DefaultPosition, wx.DefaultSize, 0 )
                self.bSizer_Ext.Add(chb)
                self.Bind(wx.EVT_CHECKBOX, self.OnCheck, chb)
            self.Layout()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am pretty new to the iOS world and since I'm coming from the
Pretty new to sqlite (and sql). Trying to modify one table using another. create
im pretty new to xcode, so sorry if these are basics but im having
I'm pretty new to mac development (coming from a web and iOS background) and
Being pretty new to C++, I don't quite understand some instructions I encounter such
pretty new to vb and I want to get a tab control working. so
Im pretty new to Java Web Services, but I cant find a good explanation
I pretty new to Objective-C (and C itself) and need to consume a NSData
I'm pretty new to my company (2 weeks) and we're starting a new platform
I'm a pretty new C# and .NET developer. I recently created an MMC snapin

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.