Hi everyone.

Im having some real head-ache inducing issues with my code. I want to update a statictext label to display the value of a slider bar.

Simple enough?

Here is my code...

Speed_Slider_Panel = wx.Panel(Automatic_Control_Panel)
                
        Speed_Slider = wx.Slider(Speed_Slider_Panel, ID_SPEED_SLIDER, 0, 0, 10,
                                 style = wx.HORIZONTAL | wx.SL_AUTOTICKS)
        Speed_Slider.SetTickFreq(1, 1)
        
        self.Bind(wx.EVT_SLIDER, self.OnSpeedSlider, id=ID_SPEED_SLIDER)

the 'family tree' goes;

self
|
Main_Panel
|
Control_Panel
|
Automatic_Control_Panel
|
Speed_Slider_Panel / Speed_Judder_Panel

This is the label;

Speed_Judder_Panel = wx.Panel(Automatic_Control_Panel)
        Speed_Judder_Sizer = wx.BoxSizer(wx.HORIZONTAL)
        
        Speed_Label = wx.StaticText(Speed_Judder_Panel, ID_SPEED_LABEL, "Speed = %d" % Speed)
        Speed_Label.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD, False))

And try as i might i cannot get the label value to change with the slider. I keep getting told various things arent defined or that certain things dont have certain attribute...

def OnSpeedSlider(self, event):
        Speed_Label.SetLabel("Speed = %d" % event.GetValue())

That snippett is wrong for sure but i dont know what to do to it to get it to work :-s


Any help is greatly appreciated!


Mark

Looks like you are working within a class and have to be more religious about using 'self.' to instance the items. If you give me your whole code, I will be able to help. Otherwise it is just guess work!

Take a look at:
http://www.daniweb.com/code/snippet403.html

Hi - thanks for the reply. Sorry took a while to get back.

import wx
import os
ID_MENU_NEW_WIZ = 101
ID_MENU_SAVE    = 102
ID_MENU_LOAD    = 103
ID_MENU_EXIT    = 104
ID_MENU_HELP    = 105
ID_MENU_ABOUT   = 106
ID_RADIO_FORWARDS   = 201
ID_RADIO_STATIONARY = 202
ID_RADIO_BACKWARDS  = 203
ID_SPEED_LABEL      = 204
ID_SPEED_SLIDER     = 301
ID_SPEED_LABEL         = 401
ID_SPEED_JUDDER_BUTTON = 402
# 501-> Reserved for Bristle manual control checkboxes
# 601-> Reserved for Cylinder manual control checkboxes
ID_ACTION_BUTTON_GO   = 701
ID_ACTION_BUTTON_STOP = 702
Speed = 3
Cylinders = 2
Bristles  = 3
 
class Frame1(wx.Frame): 
    def __init__(self, parent, title):
        wx.Frame.__init__(self, parent, -1, title, pos=(150, 150))
        Icon = wx.Icon("icon3.ico", wx.BITMAP_TYPE_ICO)
        self.SetIcon(Icon)
        
### MENU ###
        
        # Create a menubar at the top of the frame
        MenuBar = wx.MenuBar()
        FileMenu = wx.Menu()
        HelpMenu = wx.Menu() 
        # Add items to the menu
        FileMenu.Append(ID_MENU_NEW_WIZ, "&New Tractor Wizard\tCtrl-N", "Start the New Tractor wizard")
        FileMenu.Append(ID_MENU_SAVE, "&Save\tCtrl-S", "Save the current tractor configuration to file")
        FileMenu.Append(ID_MENU_LOAD, "&Load\tCtrl-L", "Open a tractor configuration from file")
        FileMenu.AppendSeparator()
        FileMenu.Append(ID_MENU_EXIT, "E&xit\tAlt-F4", "Exit the program")
        
        HelpMenu.Append(ID_MENU_HELP, "&Help\tF1", "Open the Help file")
        HelpMenu.AppendSeparator()
        HelpMenu.Append(ID_MENU_ABOUT, "&About", "About the program")
 
        # Bind the menu event to an event handler
        self.Bind(wx.EVT_MENU, self.OnMenuSave, id = ID_MENU_SAVE)
        self.Bind(wx.EVT_MENU, self.OnMenuLoad, id = ID_MENU_LOAD)
        self.Bind(wx.EVT_MENU, self.OnMenuExit, id = ID_MENU_EXIT)
        self.Bind(wx.EVT_MENU, self.OnMenuAbout, id = ID_MENU_ABOUT)
 
        # Put the menu on the menubar
        MenuBar.Append(FileMenu, "&File")
        MenuBar.Append(HelpMenu, "&Help")
        self.SetMenuBar(MenuBar)
        

### STATUS BAR ###
        
        self.CreateStatusBar()
 
### MAIN PANEL ###
        
        Main_Panel = wx.Panel(self)
        Main_Panel.SetBackgroundColour((225,245,255))
 
### TITLE PANEL ###
        
        Title_Panel = wx.Panel(Main_Panel)
 
        Title_Label = wx.StaticText(Title_Panel, -1, "Sequence Driven Controller")
        Title_Label.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.BOLD, True))
        Title_Label.SetForegroundColour('#00009F')
        Title_Image = wx.Image("DPT Image.jpg", wx.BITMAP_TYPE_ANY)
        Title_Bitmap_Widget = wx.StaticBitmap(Title_Panel, -1, wx.BitmapFromImage(Title_Image))
        Title_Sizer = wx.BoxSizer(wx.HORIZONTAL)
        Title_Sizer.Add(Title_Bitmap_Widget, 1, wx.ALIGN_CENTER)
        Title_Sizer.Add(Title_Label, 4, wx.ALIGN_CENTER | wx.LEFT, 10)
        
        Title_Panel.SetSizer(Title_Sizer)
        Title_Panel.Layout()
 
### CONTROL PANEL setup ###
        Control_Panel = wx.Panel(Main_Panel)
        Control_Sizer = wx.BoxSizer(wx.HORIZONTAL)
 
### AUTOMATIC CONTROL setup ###
        Automatic_Control_Panel = wx.Panel(Control_Panel)
        Automatic_Box = wx.StaticBox(Automatic_Control_Panel, -1, 'Automated Control')
        Automatic_Box.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD, False))
        Automatic_Control_Sizer = wx.StaticBoxSizer(Automatic_Box, wx.VERTICAL)
 
### DIRECTION PANEL ###
        Direction_Panel = wx.Panel(Automatic_Control_Panel)
        
        RadioButtonForwards = wx.RadioButton(Direction_Panel, ID_RADIO_FORWARDS, "Forwards")
        RadioButtonStationary = wx.RadioButton(Direction_Panel, ID_RADIO_STATIONARY, "Stationary")
        RadioButtonBackwards = wx.RadioButton(Direction_Panel, ID_RADIO_BACKWARDS, "Backwards")
        
        Direction_Sizer = wx.BoxSizer(wx.HORIZONTAL)
        Direction_Sizer.Add(RadioButtonForwards, 1, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 2)
        Direction_Sizer.Add(RadioButtonStationary, 1, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 2)
        Direction_Sizer.Add(RadioButtonBackwards, 1, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 2)
               
        Direction_Panel.SetSizer(Direction_Sizer)
        Direction_Panel.Layout()
 
### SPEED SLIDER & JUDDER ###
        Speed_Slider_Panel = wx.Panel(Automatic_Control_Panel)
                
        Speed_Slider = wx.Slider(Speed_Slider_Panel, ID_SPEED_SLIDER, 0, 0, 10,
                                 style = wx.HORIZONTAL | wx.SL_AUTOTICKS)
        Speed_Slider.SetTickFreq(1, 1)
        
        self.Bind(wx.EVT_SLIDER, self.OnSpeedSlider, id=ID_SPEED_SLIDER)
        
        Speed_Slider_Sizer = wx.BoxSizer(wx.HORIZONTAL) 
        Speed_Slider_Sizer.Add(Speed_Slider, -1, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 2)
        
        Speed_Slider_Panel.SetSizer(Speed_Slider_Sizer)
        Speed_Slider_Panel.Layout()
 
### SPEED & JUDDER ###
        Speed_Judder_Panel = wx.Panel(Automatic_Control_Panel)
        Speed_Judder_Sizer = wx.BoxSizer(wx.HORIZONTAL)
        
        Speed_Label = wx.StaticText(Speed_Judder_Panel, ID_SPEED_LABEL, "Speed = %d" % Speed)
        Speed_Label.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD, False))
        
        Speed_Judder_Button = wx.ToggleButton(Speed_Judder_Panel, ID_SPEED_JUDDER_BUTTON, "Judder")
        Speed_Judder_Sizer.Add(Speed_Label, 3, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 2)
        Speed_Judder_Sizer.Add(Speed_Judder_Button, 2, wx.EXPAND | wx.ALL, 2)
        Speed_Judder_Panel.SetSizer(Speed_Judder_Sizer)
        Speed_Judder_Panel.Layout()
 
### AUTOMATIC CONTROL layout ###
        Automatic_Control_Sizer.Add(Direction_Panel, 1, wx.EXPAND)
        Automatic_Control_Sizer.Add(Speed_Slider_Panel, 1, wx.EXPAND)
        Automatic_Control_Sizer.Add(Speed_Judder_Panel, 1, wx.EXPAND)
        Automatic_Control_Panel.SetSizer(Automatic_Control_Sizer)
        Automatic_Control_Sizer.Fit(self)                # Fit frame to neccessary size
        Automatic_Control_Sizer.SetSizeHints(self)       # Prevents frame from getting smaller than min.
        Automatic_Control_Panel.Layout()
 
### MANUAL CONTROL ###
        Manual_Control_Panel = wx.Panel(Control_Panel)
        Bristles_Panel = wx.Panel(Manual_Control_Panel)
        Cylinders_Panel = wx.Panel(Manual_Control_Panel)
        Manual_Box = wx.StaticBox(Manual_Control_Panel, -1, 'Manual Control')
        Manual_Box.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD, False))
        Manual_Control_Sizer = wx.StaticBoxSizer(Manual_Box, wx.HORIZONTAL)
        Bristles_Sizer = wx.BoxSizer(wx.VERTICAL)
        Cylinders_Sizer = wx.BoxSizer(wx.VERTICAL)

        # Draws manual control check boxes for the exact number of Bristles / Cylinders
        # on the machine
        
        Bristles_CheckBox = []
        Cylinders_CheckBox = []
        
        for x in range(0, Bristles):
            Bristles_CheckBox.insert(x, (wx.CheckBox(Bristles_Panel, 501+x, "Bristle %d" % (x+1))) )
            Bristles_Sizer.Add(Bristles_CheckBox[x], 1, wx.ALIGN_CENTER_HORIZONTAL)
        for x in range(0, Cylinders):
            Cylinders_CheckBox.insert(x, (wx.CheckBox(Cylinders_Panel, 601+x, "Cylinder %d" % (x+1))) )
            Cylinders_Sizer.Add(Cylinders_CheckBox[x], 1, wx.ALIGN_CENTER_HORIZONTAL)
        Bristles_Panel.SetSizer(Bristles_Sizer)
        Bristles_Panel.Layout()
        Cylinders_Panel.SetSizer(Cylinders_Sizer)
        Cylinders_Panel.Layout()
        Manual_Control_Sizer.Add(Cylinders_Panel, 1, wx.EXPAND)
        Manual_Control_Sizer.Add(Bristles_Panel, 1, wx.EXPAND)
        
        Manual_Control_Panel.SetSizer(Manual_Control_Sizer)
        Manual_Control_Panel.Layout()
                                 
        
## CONTROL PANEL layout ###
        Control_Sizer.Add(Automatic_Control_Panel, 3, wx.EXPAND | wx.ALL, 1)
        Control_Sizer.Add(Manual_Control_Panel, 2, wx.EXPAND | wx.ALL, 1)
        Control_Panel.SetSizer(Control_Sizer)
        Control_Panel.Layout()
 
### ACTION PANEL ###
        Action_Panel = wx.Panel(Main_Panel)
        Action_Button_Go = wx.Button(Action_Panel, ID_ACTION_BUTTON_GO, "GO")
        Action_Button_Go.SetBackgroundColour('Green')
        #self.Bind(wx.EVT_BUTTON, self.OnEnterGo, Action_Button_Go)
        
        Action_Button_Stop = wx.Button(Action_Panel, ID_ACTION_BUTTON_STOP, "STOP")
        Action_Button_Stop.SetBackgroundColour('Red')
        #self.Bind(wx.EVT_BUTTON, self.OnStop, id=ID_ACTION_BUTTON_STOP)
        Action_Sizer = wx.BoxSizer(wx.HORIZONTAL)
        Action_Sizer.Add(Action_Button_Go, 1, wx.EXPAND | wx.ALL, 1)
        Action_Sizer.Add(Action_Button_Stop, 1, wx.EXPAND | wx.ALL, 1)
        Action_Panel.SetSizer(Action_Sizer)
        Action_Panel.Layout()
        
    
### MAIN SIZER CONTROL ###
                
        Main_Sizer = wx.BoxSizer(wx.VERTICAL)
        Main_Sizer.Add(Title_Panel, 1, wx.EXPAND | wx.LEFT | wx.RIGHT, 10)
        Main_Sizer.Add(Control_Panel, 2, wx.EXPAND | wx.LEFT | wx.RIGHT, 10)
        Main_Sizer.Add(Action_Panel, 1, wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, 10)
        
        Main_Panel.SetSizer(Main_Sizer)
        Main_Sizer.Fit(self)                # Fit frame to neccessary size
        Main_Sizer.SetSizeHints(self)       # Prevents frame from getting smaller than min.
 

### MENU EVENTS ###
        
    def OnMenuSave(self, event):
        dlg = wx.FileDialog(self, "Save Config File...", os.getcwd(),
                            style = wx.SAVE | wx.CHANGE_DIR | wx.OVERWRITE_PROMPT)
        if dlg.ShowModal() == wx.ID_OK:
            print "Saved"
            wx.Sleep(1)
        dlg.Destroy()
    def OnMenuLoad(self, event):
        dlg = wx.FileDialog(self, "Load Config File...", os.getcwd(),
                            style = wx.OPEN | wx.CHANGE_DIR)
        if dlg.ShowModal() == wx.ID_OK:
            print "Loaded"
            wx.Sleep(1)
        dlg.Destroy()
        
    def OnMenuExit(self, event):
        self.Close()
 
    def OnMenuAbout(self, evt):
        dlg = wx.MessageDialog(self, "DPT - Sequence Driven Controller\n"
                              "Mark Walker 2006/07\n"
                              "Final Year Engineering Project", "Sequence Driven Controller",
                               wx.OK | wx.ICON_INFORMATION)
        dlg.ShowModal()
        dlg.Destroy()
 
### CONTROLLER DRIVEN EVENTS ###
    def OnSpeedSlider(self, event):
        Speed_Label.SetLabel("Speed = %d" % event.Speed_Slider.GetValue())
    
 
class wxPyApp(wx.App):
    def OnInit(self):
        frame = Frame1(None, "DPT - Sequence Driven Controller")
        self.SetTopWindow(frame)
        frame.Show(True)
        return True
        
app = wxPyApp(redirect=True)
app.MainLoop()

Im pretty sure you are right about the class thing. Just not really sure how to instance / call / define everything i need to.


Thanks again :-)


Mark

I corrected your code in a few places, added a few missing self. prefixes. If you use a widget in one of the class methods, then you have to prefix it with self.

import wx
import os

ID_MENU_NEW_WIZ = 101
ID_MENU_SAVE    = 102
ID_MENU_LOAD    = 103
ID_MENU_EXIT    = 104
ID_MENU_HELP    = 105
ID_MENU_ABOUT   = 106
ID_RADIO_FORWARDS   = 201
ID_RADIO_STATIONARY = 202
ID_RADIO_BACKWARDS  = 203
ID_SPEED_LABEL      = 204    # first time!!!!
ID_SPEED_SLIDER     = 301
#ID_SPEED_LABEL         = 401  # second time!!!!
ID_SPEED_JUDDER_BUTTON = 402
# 501-> Reserved for Bristle manual control checkboxes
# 601-> Reserved for Cylinder manual control checkboxes
ID_ACTION_BUTTON_GO   = 701
ID_ACTION_BUTTON_STOP = 702
Speed = 3
Cylinders = 2
Bristles  = 3
 
class Frame1(wx.Frame): 
    def __init__(self, parent, title):
        wx.Frame.__init__(self, parent, -1, title, pos=(150, 150))
        Icon = wx.Icon("icon3.ico", wx.BITMAP_TYPE_ICO)
        self.SetIcon(Icon)
        
### MENU ###
        
        # Create a menubar at the top of the frame
        MenuBar = wx.MenuBar()
        FileMenu = wx.Menu()
        HelpMenu = wx.Menu() 
        # Add items to the menu
        FileMenu.Append(ID_MENU_NEW_WIZ, "&New Tractor Wizard\tCtrl-N", "Start the New Tractor wizard")
        FileMenu.Append(ID_MENU_SAVE, "&Save\tCtrl-S", "Save the current tractor configuration to file")
        FileMenu.Append(ID_MENU_LOAD, "&Load\tCtrl-L", "Open a tractor configuration from file")
        FileMenu.AppendSeparator()
        FileMenu.Append(ID_MENU_EXIT, "E&xit\tAlt-F4", "Exit the program")
        
        HelpMenu.Append(ID_MENU_HELP, "&Help\tF1", "Open the Help file")
        HelpMenu.AppendSeparator()
        HelpMenu.Append(ID_MENU_ABOUT, "&About", "About the program")
 
        # Bind the menu event to an event handler
        self.Bind(wx.EVT_MENU, self.OnMenuSave, id = ID_MENU_SAVE)
        self.Bind(wx.EVT_MENU, self.OnMenuLoad, id = ID_MENU_LOAD)
        self.Bind(wx.EVT_MENU, self.OnMenuExit, id = ID_MENU_EXIT)
        self.Bind(wx.EVT_MENU, self.OnMenuAbout, id = ID_MENU_ABOUT)

        # Put the menu on the menubar
        MenuBar.Append(FileMenu, "&File")
        MenuBar.Append(HelpMenu, "&Help")
        self.SetMenuBar(MenuBar)
        
 
### STATUS BAR ###
        
        self.CreateStatusBar()
 
### MAIN PANEL ###
        
        Main_Panel = wx.Panel(self)
        Main_Panel.SetBackgroundColour((225,245,255))
 
### TITLE PANEL ###
        
        Title_Panel = wx.Panel(Main_Panel)
 
        Title_Label = wx.StaticText(Title_Panel, -1, "Sequence Driven Controller")
        Title_Label.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.BOLD, True))
        Title_Label.SetForegroundColour('#00009F')
        Title_Image = wx.Image("DPT Image.jpg", wx.BITMAP_TYPE_ANY)
        #Title_Image = wx.Image("Btn_up.JPG", wx.BITMAP_TYPE_ANY)  # for testing!!!!
        Title_Bitmap_Widget = wx.StaticBitmap(Title_Panel, -1, wx.BitmapFromImage(Title_Image))
        Title_Sizer = wx.BoxSizer(wx.HORIZONTAL)
        Title_Sizer.Add(Title_Bitmap_Widget, 1, wx.ALIGN_CENTER)
        Title_Sizer.Add(Title_Label, 4, wx.ALIGN_CENTER | wx.LEFT, 10)
        
        Title_Panel.SetSizer(Title_Sizer)
        Title_Panel.Layout()
 
### CONTROL PANEL setup ###
        Control_Panel = wx.Panel(Main_Panel)
        Control_Sizer = wx.BoxSizer(wx.HORIZONTAL)
 
### AUTOMATIC CONTROL setup ###
        Automatic_Control_Panel = wx.Panel(Control_Panel)
        Automatic_Box = wx.StaticBox(Automatic_Control_Panel, -1, 'Automated Control')
        Automatic_Box.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD, False))
        Automatic_Control_Sizer = wx.StaticBoxSizer(Automatic_Box, wx.VERTICAL)
 
### DIRECTION PANEL ###
        Direction_Panel = wx.Panel(Automatic_Control_Panel)
        
        RadioButtonForwards = wx.RadioButton(Direction_Panel, ID_RADIO_FORWARDS, "Forwards")
        RadioButtonStationary = wx.RadioButton(Direction_Panel, ID_RADIO_STATIONARY, "Stationary")
        RadioButtonBackwards = wx.RadioButton(Direction_Panel, ID_RADIO_BACKWARDS, "Backwards")
        
        Direction_Sizer = wx.BoxSizer(wx.HORIZONTAL)
        Direction_Sizer.Add(RadioButtonForwards, 1, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 2)
        Direction_Sizer.Add(RadioButtonStationary, 1, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 2)
        Direction_Sizer.Add(RadioButtonBackwards, 1, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 2)
               
        Direction_Panel.SetSizer(Direction_Sizer)
        Direction_Panel.Layout()
 
### SPEED SLIDER & JUDDER ### added a few self. !!!!
        Speed_Slider_Panel = wx.Panel(Automatic_Control_Panel)
                
        self.Speed_Slider = wx.Slider(Speed_Slider_Panel, ID_SPEED_SLIDER, 0, 0, 10,
                                 style = wx.HORIZONTAL | wx.SL_AUTOTICKS)
        self.Speed_Slider.SetTickFreq(1, 1)
        
        self.Bind(wx.EVT_SLIDER, self.OnSpeedSlider, id=ID_SPEED_SLIDER)
        
        Speed_Slider_Sizer = wx.BoxSizer(wx.HORIZONTAL) 
        Speed_Slider_Sizer.Add(self.Speed_Slider, -1, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 2)
        
        Speed_Slider_Panel.SetSizer(Speed_Slider_Sizer)
        Speed_Slider_Panel.Layout()
 
### SPEED & JUDDER ###
        Speed_Judder_Panel = wx.Panel(Automatic_Control_Panel)
        Speed_Judder_Sizer = wx.BoxSizer(wx.HORIZONTAL)
        
        self.Speed_Label = wx.StaticText(Speed_Judder_Panel, ID_SPEED_LABEL, "Speed = %d" % Speed)
        self.Speed_Label.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD, False))
        
        Speed_Judder_Button = wx.ToggleButton(Speed_Judder_Panel, ID_SPEED_JUDDER_BUTTON, "Judder")
        Speed_Judder_Sizer.Add(self.Speed_Label, 3, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 2)
        Speed_Judder_Sizer.Add(Speed_Judder_Button, 2, wx.EXPAND | wx.ALL, 2)
        Speed_Judder_Panel.SetSizer(Speed_Judder_Sizer)
        Speed_Judder_Panel.Layout()
 
### AUTOMATIC CONTROL layout ###
        Automatic_Control_Sizer.Add(Direction_Panel, 1, wx.EXPAND)
        Automatic_Control_Sizer.Add(Speed_Slider_Panel, 1, wx.EXPAND)
        Automatic_Control_Sizer.Add(Speed_Judder_Panel, 1, wx.EXPAND)
        Automatic_Control_Panel.SetSizer(Automatic_Control_Sizer)
        Automatic_Control_Sizer.Fit(self)                # Fit frame to neccessary size
        Automatic_Control_Sizer.SetSizeHints(self)       # Prevents frame from getting smaller than min.
        Automatic_Control_Panel.Layout()
 
### MANUAL CONTROL ###
        Manual_Control_Panel = wx.Panel(Control_Panel)
        Bristles_Panel = wx.Panel(Manual_Control_Panel)
        Cylinders_Panel = wx.Panel(Manual_Control_Panel)
        Manual_Box = wx.StaticBox(Manual_Control_Panel, -1, 'Manual Control')
        Manual_Box.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD, False))
        Manual_Control_Sizer = wx.StaticBoxSizer(Manual_Box, wx.HORIZONTAL)
        Bristles_Sizer = wx.BoxSizer(wx.VERTICAL)
        Cylinders_Sizer = wx.BoxSizer(wx.VERTICAL)
 
        # Draws manual control check boxes for the exact number of Bristles / Cylinders
        # on the machine
        
        Bristles_CheckBox = []
        Cylinders_CheckBox = []
        
        for x in range(0, Bristles):
            Bristles_CheckBox.insert(x, (wx.CheckBox(Bristles_Panel, 501+x, "Bristle %d" % (x+1))) )
            Bristles_Sizer.Add(Bristles_CheckBox[x], 1, wx.ALIGN_CENTER_HORIZONTAL)
        for x in range(0, Cylinders):
            Cylinders_CheckBox.insert(x, (wx.CheckBox(Cylinders_Panel, 601+x, "Cylinder %d" % (x+1))) )
            Cylinders_Sizer.Add(Cylinders_CheckBox[x], 1, wx.ALIGN_CENTER_HORIZONTAL)
        Bristles_Panel.SetSizer(Bristles_Sizer)
        Bristles_Panel.Layout()
        Cylinders_Panel.SetSizer(Cylinders_Sizer)
        Cylinders_Panel.Layout()
        Manual_Control_Sizer.Add(Cylinders_Panel, 1, wx.EXPAND)
        Manual_Control_Sizer.Add(Bristles_Panel, 1, wx.EXPAND)
        
        Manual_Control_Panel.SetSizer(Manual_Control_Sizer)
        Manual_Control_Panel.Layout()
                                 
        
## CONTROL PANEL layout ###
        Control_Sizer.Add(Automatic_Control_Panel, 3, wx.EXPAND | wx.ALL, 1)
        Control_Sizer.Add(Manual_Control_Panel, 2, wx.EXPAND | wx.ALL, 1)
        Control_Panel.SetSizer(Control_Sizer)
        Control_Panel.Layout()
 
### ACTION PANEL ###
        Action_Panel = wx.Panel(Main_Panel)
        Action_Button_Go = wx.Button(Action_Panel, ID_ACTION_BUTTON_GO, "GO")
        Action_Button_Go.SetBackgroundColour('Green')
        #self.Bind(wx.EVT_BUTTON, self.OnEnterGo, Action_Button_Go)
        
        Action_Button_Stop = wx.Button(Action_Panel, ID_ACTION_BUTTON_STOP, "STOP")
        Action_Button_Stop.SetBackgroundColour('Red')
        #self.Bind(wx.EVT_BUTTON, self.OnStop, id=ID_ACTION_BUTTON_STOP)
        Action_Sizer = wx.BoxSizer(wx.HORIZONTAL)
        Action_Sizer.Add(Action_Button_Go, 1, wx.EXPAND | wx.ALL, 1)
        Action_Sizer.Add(Action_Button_Stop, 1, wx.EXPAND | wx.ALL, 1)
        Action_Panel.SetSizer(Action_Sizer)
        Action_Panel.Layout()
        
    
### MAIN SIZER CONTROL ###
                
        Main_Sizer = wx.BoxSizer(wx.VERTICAL)
        Main_Sizer.Add(Title_Panel, 1, wx.EXPAND | wx.LEFT | wx.RIGHT, 10)
        Main_Sizer.Add(Control_Panel, 2, wx.EXPAND | wx.LEFT | wx.RIGHT, 10)
        Main_Sizer.Add(Action_Panel, 1, wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, 10)
        
        Main_Panel.SetSizer(Main_Sizer)
        Main_Sizer.Fit(self)                # Fit frame to neccessary size
        Main_Sizer.SetSizeHints(self)       # Prevents frame from getting smaller than min.
 
 
### MENU EVENTS ###
        
    def OnMenuSave(self, event):
        dlg = wx.FileDialog(self, "Save Config File...", os.getcwd(),
                            style = wx.SAVE | wx.CHANGE_DIR | wx.OVERWRITE_PROMPT)
        if dlg.ShowModal() == wx.ID_OK:
            print "Saved"
            wx.Sleep(1)
        dlg.Destroy()
        
    def OnMenuLoad(self, event):
        dlg = wx.FileDialog(self, "Load Config File...", os.getcwd(),
                            style = wx.OPEN | wx.CHANGE_DIR)
        if dlg.ShowModal() == wx.ID_OK:
            print "Loaded"
            wx.Sleep(1)
        dlg.Destroy()
        
    def OnMenuExit(self, event):
        self.Close()
 
    def OnMenuAbout(self, evt):
        dlg = wx.MessageDialog(self, "DPT - Sequence Driven Controller\n"
                              "Mark Walker 2006/07\n"
                              "Final Year Engineering Project", "Sequence Driven Controller",
                               wx.OK | wx.ICON_INFORMATION)
        dlg.ShowModal()
        dlg.Destroy()
 
### CONTROLLER DRIVEN EVENTS ###  added a few self. !!!!
    def OnSpeedSlider(self, event):
        self.Speed_Label.SetLabel("Speed = %d" % self.Speed_Slider.GetValue())
    
 
class wxPyApp(wx.App):
    def OnInit(self):
        frame = Frame1(None, "DPT - Sequence Driven Controller")
        self.SetTopWindow(frame)
        frame.Show(True)
        return True
        
#app = wxPyApp(redirect=True)
app = wxPyApp(redirect=False)  # so error messages will show up in DrPython
app.MainLoop()
commented: Massively helpful! Thankyou! +1

You are an absolutle legend!

Thankyou SO much! :-)

Is it good practice in that case to preceed any widget with 'self'?

I think i have failed to realise the significance of 'self' when teaching myself the language.

Once again, thankyou :-)


Mark

Well, you can print self and in your code find out that it is simply the instance __main__.Frame1 . Blindly putting 'self.' in front of every variable would be an overkill. It only is needed if there has to be a reference to a particular instance, or you want to use that variable in one of your class methods. Remember, methods are functions within the class and they always start with argument self.

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.