forked from pythonnet/pythonnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelloform.py
More file actions
69 lines (54 loc) · 2.23 KB
/
helloform.py
File metadata and controls
69 lines (54 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# ===========================================================================
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
# ===========================================================================
import clr
SWF = clr.AddReference("System.Windows.Forms")
print SWF.Location
import System.Windows.Forms as WinForms
from System.Drawing import Size, Point
class HelloApp(WinForms.Form):
"""A simple hello world app that demonstrates the essentials of
winforms programming and event-based programming in Python."""
def __init__(self):
self.Text = "Hello World From Python"
self.AutoScaleBaseSize = Size(5, 13)
self.ClientSize = Size(392, 117);
h = WinForms.SystemInformation.CaptionHeight
self.MinimumSize = Size(392, (117 + h))
# Create the button
self.button = WinForms.Button()
self.button.Location = Point(160, 64)
self.button.Size = Size(820, 20)
self.button.TabIndex = 2
self.button.Text = "Click Me!"
# Register the event handler
self.button.Click += self.button_Click
# Create the text box
self.textbox = WinForms.TextBox()
self.textbox.Text = "Hello World"
self.textbox.TabIndex = 1
self.textbox.Size = Size(1260, 40)
self.textbox.Location = Point(160, 24)
# Add the controls to the form
self.AcceptButton = self.button
self.Controls.Add(self.button);
self.Controls.Add(self.textbox);
def button_Click(self, sender, args):
"""Button click event handler"""
print "Click"
WinForms.MessageBox.Show("Please do not press this button again.")
def run(self):
WinForms.Application.Run(self)
def main():
form = HelloApp()
print "form created"
app = WinForms.Application
print "app referenced"
app.Run(form)
if __name__ == '__main__':
main()