Hi there,

I would like to be able to change a button during the runtime of a gui. I can change the value no problem (set Label) but I need to change the size of the button as well. I have managed to change it with SetSize((120, 30)) but then the button scoots under the next button along.

I would like to change the self.okay_button's value from "OK" to "Edit Birdlist" and it will need to be much wider.

I have tried to use Show/Hide, but then the new button gets put right up at the top of the gui.

Do I need to put my buttons inside another sizer? What is the best way to do this.

I also need to be able to change the even, but I think that should be rather easy? But I would appreciate comments on that.

#Buttons
        hbox_buttons = wx.BoxSizer(wx.HORIZONTAL)
        #### Here is the part I want to be able to change
        self.okay_button = wx.Button(self.panel, -1, "OK", size=(70, 30))
        hbox_buttons.Add(self.okay_button, 0)
        ####
        html_button = wx.Button(self.panel, -1, "Build HTML", size=(120, 30))
        hbox_buttons.Add(html_button, 0)
        exit_button = wx.Button(self.panel, -1, "Close", size=(70, 30))
        hbox_buttons.Add(exit_button, 0)
        vbox.Add(hbox_buttons, 0, wx.ALIGN_RIGHT | wx.RIGHT, 10)
        self.Bind(wx.EVT_BUTTON, self.getData, id=self.okay_button.GetId())
        #I will need a button event: self.ChangeBirdlist
        #when this usually  hidden button is there.
        self.Bind(wx.EVT_BUTTON, self.getHtml, id=html_button.GetId())
        self.Bind(wx.EVT_BUTTON, self.OnQuit, id=exit_button.GetId())

Could be as simple as using

"     OK      "  that has the size of 
"Edit Birdlist"

I didn't really get it right to change or dynamically resize the buttons. So I just compormized - set the value of the 'OK' button to just the right size to fit the full text. It's a pitty. Perhaps some other time I will play with it again until I get it right. But I wasn't getting it right with Show() and Hide(), and when I started with more sizers inside the existing sizers it starts to just get to be a lot of code that I would rather do without at this point.

For the second part it was rather easy. I set a counter, and instead of setting an if/else to choose the event within the sizer's code, I set a standard method call from the even to a small method where I then select which method to call from there, using the counter.

The second part was easy and I am happy with my solution, but the first part, I am sure that there must be something that I am missing. If anyone has an answer at a later stage, or a suggestion as to how I should ask the question to make it more clear, please let me know. I will keep this post unsolved for the time being, despite going on with my project.

Could be as simple as using

"     OK      "  that has the size of 
"Edit Birdlist"

Well, that's kind of what I have done. It just would be 'nice' to have the "OK" button smaller most of the time, but no biggie. I think coming more from web stuff I just assume that these things are as easy to in wxPython as they are in JavaScript or CSS.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.