The following defines the creation of a Button in a Panel or Form derived
class. # Create the command button
self.resetButton = WinForms.Button()
self.resetButton.Parent = self
self.resetButton.Size = Size(80,25)
self.resetButton.Location = Point((self.Width-self.resetButton.Width)/2,(self.Height-self.resetButton.Height*3/2))
self.resetButton.Text = "Reset"
# Register event handler for Button.Click
self.resetButton.Click += self.ResetButton_ClickHandler
# Register event handler for Resize
self.Resize += self.ResizeHandler
def ResizeHandler(self, sender, args):
# Handles the Resize event
print 'Resize Left: ',self.Left
print 'Resize Top: ',self.Top
print 'Resize Width: ',self.Width
print 'Resize Height: ',self.Height
self.resetButton.Location = Point((self.Width-self.resetButton.Width)/2,(self.Height - self.resetButton.Height*3/2))
def ResetButton_ClickHandler(self, sender, args):
# Handles the command button Click event
print 'Button Click'
Example 1: Change Font
self.resetButton.ForeColor = Color.Yellow
self.resetButton.Font = Font(r"Arial",20.0,FontStyle.Bold)
Example 2: Set Image
# handle the exception no image available
try :
self.resetButton.Image = Bitmap(r'\video.jpg')
except :
print ' no \video.jpg present '
|