Custom (windows) form

#This script creates a form with a button. When the button is clicked, captures the time when it was clicked.

import time
import clr
clr.AddReference('System.Windows.Forms')
from System.Windows.Forms import Application, Button, Form

#A. create a blank form
form = Form()
form.Text = 'Hello World'

#B. Create a button to add to the form
#B.1 Define what button will do when clicked
def onClick(sender, eventArgs):
   form.Text = 'Thanks for clicking at ' + time.asctime()
   print time.asctime()

#B.2 Create new button and tell what function to call when clicked
button = Button(Text="Please click")
button.Click += onClick

#B.3 Add button to form
#add button to form
form.Controls.Add(button)

#C. show the form
form.ShowDialog()

Previous
Next Post »