wxPython - cannot press on BUTTON or move SLIDER

I have created a GUI with a great layout using wxPython. However, button and slider don’t work in one of the panels. Please provide some guidance for me. (code runs fine, but button cannot be pressed and cannot move slider) I am running it on Windows 7, Python 2.7.5, wxPython 2.8.12.1 (msw-unicode)

import wx
class MainWindow(wx.Frame):

    def __init__(self, *args, **kwargs):
        super(MainWindow, self).__init__(*args, **kwargs)

        self.InitUI()

    def InitUI(self):
        self.SetSize((1300, 700))
        self.SetTitle('GUI made by James')

        self.panel = wx.Panel(self)
        self.panel.SetBackgroundColour('#4f5049')
        mainPanel = wx.Panel(self.panel)
        mainPanel.SetBackgroundColour('#ededed')

        sub_vbox = wx.BoxSizer(wx.VERTICAL)
        subPanel_top = wx.Panel(mainPanel)

        hbox = wx.BoxSizer(wx.HORIZONTAL)
        hierarchy_browser = wx.TextCtrl(subPanel_top, style = wx.TE_MULTILINE)
        hbox.Add(hierarchy_browser, proportion = 1, flag = wx.TOP | wx.BOTTOM | wx.LEFT | wx.EXPAND, border = 10)
        subPanel_right = wx.Panel(mainPanel)
        wx.StaticText(subPanel_right, -1, "This is custom static text", (10, 10), (300, -1), wx.ALIGN_CENTER)
        button = wx.Button(subPanel_right, label = "exit", pos = (500, 100), size = (60, 60)) #can't press for some reason
        slider = wx.Slider(subPanel_right, -1, 50, 1, 100, pos = (320, 10), size = (250, -1), style = wx.SL_AUTOTICKS | wx.SL_LABELS)  # can't slide for some reason
        slider.SetTickFreq(5, 1)

        hbox.Add(subPanel_right, proportion = 1, flag = wx.TOP | wx.BOTTOM | wx.LEFT | wx.EXPAND, border = 10)
        subPanel_top.SetSizer(hbox)

        sub_vbox.Add(subPanel_top, 1, wx.EXPAND)

        subPanel_bottom = wx.Panel(mainPanel)
        text_entry = wx.TextCtrl(subPanel_bottom, style = wx.TE_MULTILINE)
        text_sizer = wx.BoxSizer()  # use sizer to expand TextCtrl
        text_sizer.Add(text_entry, 1, flag = wx.LEFT | wx.RIGHT |  wx.BOTTOM | wx.EXPAND, border = 10)
        subPanel_bottom.SetSizerAndFit(text_sizer)
        sub_vbox.Add(subPanel_bottom, 1, wx.EXPAND)
        mainPanel.SetSizer(sub_vbox)

        vbox = wx.BoxSizer(wx.VERTICAL)
        vbox.Add(mainPanel, 1, wx.EXPAND | wx.ALL, 10)
        self.panel.SetSizer(vbox)

        self.Bind(wx.EVT_BUTTON, self.closebutton, button)
        self.Bind(wx.EVT_CLOSE, self.closewindow)

        self.Centre()
        self.Show(True)

    def closebutton(self, event):
        self.Close(True)

    def closewindow(self, event):
        self.Destroy()

def main():
    ex = wx.App()
    MainWindow(None)
    ex.MainLoop()

if __name__ == '__main__':
    main()

You need to change this line:
subPanel_right = wx.Panel(mainpanel)
to:
subPanel_right = wx.Panel(subPanel_top)
‘subPanel_right’ was later on added to the ‘hbox’ sizer which is
managing the layout of ‘subPanel_top’ and not of ‘mainpanel’, I am
surprised that this did not cause a crash of some sort.
I used the WIT ()
to check the hierarchy of the widgets and sizers.
I also had to change this line:
slider.SetTickFreq(5, 1)
to:
slider.SetTickFreq(5)
You might also want to check out SizedControls, makes the setting up
of sizer controlled layouts a lot easier -
Werner

buttonProblem.py (2.43 KB)

···

On 04/11/2013 06:40, James Un wrote:

        I have created a

GUI with a great layout using wxPython. However, button and
slider don’t work in one of the panels. Please provide some
guidance for me. (code runs fine, but button cannot be
pressed and cannot move slider) I am running it on Windows
7, Python 2.7.5, wxPython 2.8.12.1
(msw-unicode)

http://wiki.wxpython.org/Widget%20Inspection%20Tool

http://wiki.wxpython.org/SizedControls

``