How to disable a button control in wxPython?
eriggs
eriggs at kollmorgen.com
Fri Feb 15 12:00:27 EST 2002
I'm somewhat new to Python, and I'm trying to figure out how to
disable a button control. I have included my test source code for
reference. Thanks in advance for any help offered. -- Earl
######################################################################
from wxPython.wx import *
class ButtonFrame(wxFrame):
'Creates a frame with a single button in the center'
def __init__(self):
wxFrame.__init__(self, NULL, -1, 'wxPython',
wxDefaultPosition, (330, 210))
panel = wxPanel(self, -1)
#wxTextCtrl(wxWindow* parent, wxWindowID id,
# const wxString& value = "",
# const wxPoint& pos,
# const wxSize& size = wxDefaultSize,
# long style = 0, const wxValidator& validator,
# const wxString& name = "text")
tc = wxTextCtrl(panel, -1, "", wxPoint(10, 10), \
wxSize(300, 100), wxTE_MULTILINE|wxTE_READONLY)
self.msgtext = tc
button1 = wxButton(panel, 111, 'Start', wxPoint(10, 130), \
wxSize(100, 30))
EVT_BUTTON(self, 111, self.onButtonStart)
button1.SetDefault()
self.StartButton = button1
button2 = wxButton(panel, 112, 'Quit', wxPoint(210, 130), \
wxSize(100, 30))
EVT_BUTTON(self, 112, self.onButtonQuit)
EVT_CLOSE(self, self.OnCloseWindow)
self.QuitButton = button2
# Disable Quit button
#self.QuitButton.Disable()
# Enable Start button
#self.StartButton.Enable()
def onButtonStart(self, event):
'Create a message dialog when the button is clicked'
dlg = wxMessageDialog(self, 'Starting...',\
'Start', wxOK)
dlg.ShowModal()
dlg.Destroy()
self.setText("Starting program...")
# Enable Quit button
#self.QuitButton.Enable()
# Disable Start button
#self.StartButton.Disable()
# Start program loop
def onButtonQuit(self, event):
'Create a message dialog when the button is clicked'
dlg = wxMessageDialog(self, 'Quitting...',\
'Stop', wxOK)
dlg.ShowModal()
dlg.Destroy()
self.setText("Stopping program...")
self.Close(true)
def OnCloseWindow(self, event):
self.Destroy()
def setText(self, msg):
'Create a message dialog when the button is clicked'
self.msgtext.Clear()
self.msgtext.AppendText(msg)
class App(wxApp):
def OnInit(self):
'Create the main window and insert the custom frame'
frame = ButtonFrame()
frame.Show(true)
return true # Yes, continue processing
# Create the app and start processing messages
app = App(0)
app.MainLoop()
More information about the Python-list
mailing list