如何在wxPython中强制关闭小部件

如何在wxPython中强制关闭小部件,python,user-interface,wxpython,Python,User Interface,Wxpython,我正在用wxWidgets(wxPython)为我的python项目构建GUI。有一个小问题我似乎想不出来,但很烦人。“开始”、“交叉”和“浏览”三个按钮应位于窗口底部。这些是wx.ToggleButton小部件,它们属于水平BoxSizer,而水平BoxSizer又是垂直BoxSizer的子项,名为leftmost\u box。 问题是,如何将这些按钮向下压到最左边的角落?我尝试设置标志,即wx.ALIGN\u BOTTOM,但它不起作用 附加源代码也 导入wx ##############

我正在用wxWidgets(wxPython)为我的python项目构建GUI。有一个小问题我似乎想不出来,但很烦人。“开始”、“交叉”和“浏览”三个按钮应位于窗口底部。这些是
wx.ToggleButton
小部件,它们属于水平
BoxSizer
,而水平
BoxSizer
又是垂直
BoxSizer
的子项,名为
leftmost\u box
。 问题是,如何将这些按钮向下压到最左边的角落?我尝试设置标志,即
wx.ALIGN\u BOTTOM
,但它不起作用

附加源代码也

导入wx
#################################
#设置应用程序窗口#
#################################
app=wx.app()
大型机=wx.Frame(无,-1)
大型机。设置大小((900500))
mainframe.SetTitle('Mdl'))
panel=wx.panel(主机,-1)
面板.立根底色(“灰色”)
#设置默认字体#
#字体(点大小、族、样式、重量、faceName=“”)
SetFont(wx.Font(14,wx.DEFAULT,wx.NORMAL,wx.LIGHT,faceName='Helvetica'))
####################
#全局变量#
####################
选项=['SAT考试','Top 300','Custom Dictionary','Advanced English']
word of the_of the_day=wx.StaticText(面板,标签='Profess:某一特定活动或领域的技能或专长:她的烹饪能力',大小=(180190))
#测试用一次性var
_word of the_of the_day=wx.StaticText(面板,标签='Profess:某一特定活动或领域的技能或专长:她的烹饪能力',大小=(180190))
####################
#控制在这里#
####################
searchbar_wgt=wx.SearchCtrl(面板,值='Search…',大小=(210,-1))
选择活动字典(面板,选项=选项,大小=(170,-1))
活动的\u字典\u大小\u wgt=wx.SpinCtrl(面板,最小值=0,最大值=50,初始值=15,大小=(50,-1))
按钮(面板,标签='next>')
按钮返回wgt=wx。按钮(面板,标签=“
您的
比例
值在尺寸测量器中到处都是,
标记
条目在一定程度上也是如此

  • 清理
    比例
  • 添加“下一步”和“上一步”按钮(您忘了将它们添加到尺寸器中)
  • 将一个虚拟项目添加到最左侧的\u框中,比例=1(将最后一个项目强制到底部)
  • 将扩展标志添加到主尺寸器时,在最左侧的\u框上设置扩展标志
  • 我想就这些了

    import wx
    
    #################################
    # Set up the application window #
    #################################
    
    app = wx.App()
    mainframe = wx.Frame(None, -1)
    mainframe.SetSize((900, 500))
    mainframe.SetTitle('Mdl')
    panel = wx.Panel(mainframe, -1)
    panel.SetBackgroundColour('grey')
    
    # Setting the default font #
    #wx.Font(pointSize, family, style,  weight, faceName="")
    panel.SetFont(wx.Font(14, wx.DEFAULT, wx.NORMAL, wx.LIGHT, faceName = 'Helvetica'))
    
    
    ####################
    # Global variables #
    ####################
    
    choices = ['SAT Exam', 'Top 300', 'Custom Dictionary', 'Advanced English']
    word_of_the_day   = wx.StaticText(panel, label = 'Prowess: skill or expertise in a particular activity or field: her culinary prowess.', size = (180, 190))
    
    #Throwaway var for testing
    _word_of_the_day   = wx.StaticText(panel, label = 'Prowess: skill or expertise in a particular activity or field: her culinary prowess.', size = (180, 190))
    
    ####################
    # Controls go here #
    ####################
    
    searchbar_wgt                = wx.SearchCtrl(panel, value = 'Search...', size = (210, -1))
    pick_active_dictionary_wgt   = wx.Choice(panel, choices = choices, size = (170, -1))
    active_dictionary_size_wgt   = wx.SpinCtrl(panel, min = 0, max = 50, initial = 15, size = (50, -1))
    button_next_wgt              = wx.Button(panel, label = 'Next >')
    button_back_wgt              = wx.Button(panel, label = '< Back')
    set_word_order_wgt           = wx.RadioBox(panel, label = 'Order', choices = ['Normal', 'Random'])
    logo_image                   = wx.Image('logo.png', wx.BITMAP_TYPE_ANY).Scale(285, 63)
    bitmap_logo_image            = wx.StaticBitmap(panel, -1, logo_image.ConvertToBitmap())
    start_mode_button_wgt        = wx.ToggleButton(panel, label = 'Start')
    crossword_mode_button_wgt    = wx.ToggleButton(panel, label = 'Cross')
    browse_mode_button_wgt       = wx.ToggleButton(panel, label = 'Browse')
    
    
    ###################
    # Standard Layout #
    ###################
    
    main_box      = wx.BoxSizer(wx.HORIZONTAL)
    leftmost_box  = wx.BoxSizer(wx.VERTICAL)
    central_box   = wx.BoxSizer(wx.VERTICAL)
    rightmost_box = wx.BoxSizer(wx.VERTICAL)
    
    #############
    # Subsizers #
    #############
    leftmost_box_subsizer   = wx.BoxSizer(wx.HORIZONTAL)
    
    static_box_central      = wx.StaticBox(panel, label = 'Card #', size = (180, 180))
    static_box_szr_central  = wx.StaticBoxSizer(static_box_central, wx.VERTICAL)
    
    static_box_left         = wx.StaticBox(panel, label = 'Vocabulary Options')
    static_box_szr_left     = wx.StaticBoxSizer(static_box_left, wx.VERTICAL)
    
    static_box_right        = wx.StaticBox(panel, label = 'Word of the Day', size = (200, 200))
    static_box_szr_right    = wx.StaticBoxSizer(static_box_right, wx.VERTICAL)
    
    
    static_box_szr_right.Add(word_of_the_day, 0, wx.ALL, 5)
    static_box_szr_left.AddMany([
                               (    pick_active_dictionary_wgt, 0, wx.ALL, 5 ),
                               (    active_dictionary_size_wgt, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ALIGN_RIGHT, 5 ),
                               (    set_word_order_wgt, 0, wx.LEFT|wx.RIGHT|wx.ALIGN_RIGHT, 5 )
                               ])
    
    # Changes the Label (NB: StaticBox can be reused to display definitions)
    # static_box.SetLabel('Definition')
    # To create an SB widget, you need to create an SBS and pass an SB to it as an argument
    # It will then behave as a regular sizer
    
    main_box.AddMany([
                    (   leftmost_box,   0, wx.EXPAND|wx.ALL, 10 ),
                    (   central_box,    0, wx.TOP|wx.BOTTOM, 10 ),
                    (   rightmost_box,  0, wx.ALL,           10 )
                    ])
    
    static_box_szr_central.Add(_word_of_the_day, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5)
    
    # Building the rightmost box
    rightmost_box.Add(button_next_wgt, 0, wx.ALL|wx.ALIGN_LEFT, 10)
    rightmost_box.Add(searchbar_wgt, 0, wx.ALIGN_RIGHT)
    rightmost_box.Add(static_box_szr_right, 0, wx.TOP|wx.ALIGN_RIGHT, 50)
    
    # Building the leftmost box
    leftmost_box.Add(button_back_wgt, 0, wx.ALL|wx.ALIGN_LEFT, 10)
    leftmost_box.Add(static_box_szr_left, 0, wx.ALL|wx.ALIGN_LEFT, 10)
    leftmost_box.Add((-1,-1), proportion=1)
    leftmost_box.Add(leftmost_box_subsizer, 0, wx.ALL|wx.EXPAND, 10)
    
    # Building the leftmost subsizer
    leftmost_box_subsizer.AddMany([
                                 (  start_mode_button_wgt,     wx.TOP|wx.BOTTOM|wx.ALIGN_BOTTOM, 10 ),
                                 (  crossword_mode_button_wgt, wx.TOP|wx.BOTTOM|wx.ALIGN_BOTTOM, 10 ),
                                 (  browse_mode_button_wgt,    wx.TOP|wx.BOTTOM|wx.ALIGN_BOTTOM, 10 )
                                 ])
    
    #Toggle the start mode button
    start_mode_button_wgt.SetValue(True)
    
    # The pLexis logo
    central_box.Add(bitmap_logo_image, 0, wx.ALL|wx.ALIGN_CENTRE, 5)
    # The word card
    central_box.Add(static_box_szr_central, 0, wx.ALL|wx.ALIGN_CENTRE, 5)
    
    # Kick it!
    panel.SetSizer(main_box)
    mainframe.Show()
    app.MainLoop()
    
    导入wx
    #################################
    #设置应用程序窗口#
    #################################
    app=wx
    
    import wx
    
    #################################
    # Set up the application window #
    #################################
    
    app = wx.App()
    mainframe = wx.Frame(None, -1)
    mainframe.SetSize((900, 500))
    mainframe.SetTitle('Mdl')
    panel = wx.Panel(mainframe, -1)
    panel.SetBackgroundColour('grey')
    
    # Setting the default font #
    #wx.Font(pointSize, family, style,  weight, faceName="")
    panel.SetFont(wx.Font(14, wx.DEFAULT, wx.NORMAL, wx.LIGHT, faceName = 'Helvetica'))
    
    
    ####################
    # Global variables #
    ####################
    
    choices = ['SAT Exam', 'Top 300', 'Custom Dictionary', 'Advanced English']
    word_of_the_day   = wx.StaticText(panel, label = 'Prowess: skill or expertise in a particular activity or field: her culinary prowess.', size = (180, 190))
    
    #Throwaway var for testing
    _word_of_the_day   = wx.StaticText(panel, label = 'Prowess: skill or expertise in a particular activity or field: her culinary prowess.', size = (180, 190))
    
    ####################
    # Controls go here #
    ####################
    
    searchbar_wgt                = wx.SearchCtrl(panel, value = 'Search...', size = (210, -1))
    pick_active_dictionary_wgt   = wx.Choice(panel, choices = choices, size = (170, -1))
    active_dictionary_size_wgt   = wx.SpinCtrl(panel, min = 0, max = 50, initial = 15, size = (50, -1))
    button_next_wgt              = wx.Button(panel, label = 'Next >')
    button_back_wgt              = wx.Button(panel, label = '< Back')
    set_word_order_wgt           = wx.RadioBox(panel, label = 'Order', choices = ['Normal', 'Random'])
    logo_image                   = wx.Image('logo.png', wx.BITMAP_TYPE_ANY).Scale(285, 63)
    bitmap_logo_image            = wx.StaticBitmap(panel, -1, logo_image.ConvertToBitmap())
    start_mode_button_wgt        = wx.ToggleButton(panel, label = 'Start')
    crossword_mode_button_wgt    = wx.ToggleButton(panel, label = 'Cross')
    browse_mode_button_wgt       = wx.ToggleButton(panel, label = 'Browse')
    
    
    ###################
    # Standard Layout #
    ###################
    
    main_box      = wx.BoxSizer(wx.HORIZONTAL)
    leftmost_box  = wx.BoxSizer(wx.VERTICAL)
    central_box   = wx.BoxSizer(wx.VERTICAL)
    rightmost_box = wx.BoxSizer(wx.VERTICAL)
    
    #############
    # Subsizers #
    #############
    leftmost_box_subsizer   = wx.BoxSizer(wx.HORIZONTAL)
    
    static_box_central      = wx.StaticBox(panel, label = 'Card #', size = (180, 180))
    static_box_szr_central  = wx.StaticBoxSizer(static_box_central, wx.VERTICAL)
    
    static_box_left         = wx.StaticBox(panel, label = 'Vocabulary Options')
    static_box_szr_left     = wx.StaticBoxSizer(static_box_left, wx.VERTICAL)
    
    static_box_right        = wx.StaticBox(panel, label = 'Word of the Day', size = (200, 200))
    static_box_szr_right    = wx.StaticBoxSizer(static_box_right, wx.VERTICAL)
    
    
    static_box_szr_right.Add(word_of_the_day, 0, wx.ALL, 5)
    static_box_szr_left.AddMany([
                               (    pick_active_dictionary_wgt, 0, wx.ALL, 5 ),
                               (    active_dictionary_size_wgt, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ALIGN_RIGHT, 5 ),
                               (    set_word_order_wgt, 0, wx.LEFT|wx.RIGHT|wx.ALIGN_RIGHT, 5 )
                               ])
    
    # Changes the Label (NB: StaticBox can be reused to display definitions)
    # static_box.SetLabel('Definition')
    # To create an SB widget, you need to create an SBS and pass an SB to it as an argument
    # It will then behave as a regular sizer
    
    main_box.AddMany([
                    (   leftmost_box,   0, wx.EXPAND|wx.ALL, 10 ),
                    (   central_box,    0, wx.TOP|wx.BOTTOM, 10 ),
                    (   rightmost_box,  0, wx.ALL,           10 )
                    ])
    
    static_box_szr_central.Add(_word_of_the_day, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5)
    
    # Building the rightmost box
    rightmost_box.Add(button_next_wgt, 0, wx.ALL|wx.ALIGN_LEFT, 10)
    rightmost_box.Add(searchbar_wgt, 0, wx.ALIGN_RIGHT)
    rightmost_box.Add(static_box_szr_right, 0, wx.TOP|wx.ALIGN_RIGHT, 50)
    
    # Building the leftmost box
    leftmost_box.Add(button_back_wgt, 0, wx.ALL|wx.ALIGN_LEFT, 10)
    leftmost_box.Add(static_box_szr_left, 0, wx.ALL|wx.ALIGN_LEFT, 10)
    leftmost_box.Add((-1,-1), proportion=1)
    leftmost_box.Add(leftmost_box_subsizer, 0, wx.ALL|wx.EXPAND, 10)
    
    # Building the leftmost subsizer
    leftmost_box_subsizer.AddMany([
                                 (  start_mode_button_wgt,     wx.TOP|wx.BOTTOM|wx.ALIGN_BOTTOM, 10 ),
                                 (  crossword_mode_button_wgt, wx.TOP|wx.BOTTOM|wx.ALIGN_BOTTOM, 10 ),
                                 (  browse_mode_button_wgt,    wx.TOP|wx.BOTTOM|wx.ALIGN_BOTTOM, 10 )
                                 ])
    
    #Toggle the start mode button
    start_mode_button_wgt.SetValue(True)
    
    # The pLexis logo
    central_box.Add(bitmap_logo_image, 0, wx.ALL|wx.ALIGN_CENTRE, 5)
    # The word card
    central_box.Add(static_box_szr_central, 0, wx.ALL|wx.ALIGN_CENTRE, 5)
    
    # Kick it!
    panel.SetSizer(main_box)
    mainframe.Show()
    app.MainLoop()