Sunday, September 27, 2015

IronPython: creating a GUI in Visual Studio

#Here's how you create a window with IronPython in Visual Studio

import sys import clr clr.AddReference("System.Drawing") clr.AddReference("System.Windows.Forms") from System.Drawing import Point from System.Windows.Forms import Application, Button, Form, Label, TextBox class MacsTest(Form): def __init__(self): self.Text = "GUI Tutorial" self.Height, self.Width = 250, 250 self.label = Label(); self.label.Text = "Hello"; self.label.Location = Point(50, 50) self.label.AutoSize = True self.textbox = TextBox() self.textbox.Width,self.textbox.Height = 100, 50; self.textbox.Location = Point(100, 50) self.textbox.KeyUp += self.handleKeyPress self.lblCharCounts = Label(); self.lblCharCounts.Text = "No chars"; self.lblCharCounts.Location = Point(50, 100) self.lblCharCounts.AutoSize = True self.Controls.Add(self.label) self.Controls.Add(self.textbox) self.Controls.Add(self.lblCharCounts) def handleKeyPress(self, sender, args): self.lblCharCounts.Text = "{0} chars".format(len(self.textbox.Text)) Application.EnableVisualStyles() Application.SetCompatibleTextRenderingDefault(False) form = MacsTest() Application.Run(form)

#Reference: http://www.voidspace.org.uk/ironpython/winforms/index.shtml




No comments:

Post a Comment

There was an error in this gadget