# First Python Form - SharpDevelop

**URL:** <https://discourse.mcneel.com/t/first-python-form-sharpdevelop/20276>\
**Category:** Scripting\
**Created:** [May 17, 2015, 7:01am UTC](https://discourse.mcneel.com/t/first-python-form-sharpdevelop/20276 "2015-05-17T07:01:00Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![KeithR](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/keithr/32/771243_2.png) [@KeithR](https://discourse.mcneel.com/u/KeithR)\
**Post date:** [May 17, 2015, 7:01am UTC](https://discourse.mcneel.com/t/first-python-form-sharpdevelop/20276/1 "2015-05-17T07:01:00Z")

</div>

Here is the code to my first Python Form using ( SharpDevelop - [www.icsharpcode.net/opensource/sd/](http://www.icsharpcode.net/opensource/sd/) )

The code below runs from the EditPythonScript command

How do I get the input text from this Form and place it into a variable - after pressing the Submit button ?

thx Keith

```
import System.Drawing
import System.Windows.Forms

from System.Drawing import *
from System.Windows.Forms import *

class MainForm(Form):
	def __init__ (self):
		self.InitializeComponent()
	
	def InitializeComponent(self):
		self._textBox1 = System.Windows.Forms.TextBox()
		self._label1 = System.Windows.Forms.Label()
		self._label2 = System.Windows.Forms.Label()
		self._textBox2 = System.Windows.Forms.TextBox()
		self._button1 = System.Windows.Forms.Button()
		self.SuspendLayout()
		# 
		# label1
		# 
		self._label1.Location = System.Drawing.Point(40, 39)
		self._label1.Name = "label1"
		self._label1.Size = System.Drawing.Size(100, 20)
		self._label1.TabIndex = 4
		self._label1.Text = "label1"
		# 
		# label2
		# 
		self._label2.Location = System.Drawing.Point(40, 88)
		self._label2.Name = "label2"
		self._label2.Size = System.Drawing.Size(100, 20)
		self._label2.TabIndex = 3
		self._label2.Text = "label2"
		# 
		# textBox1
		# 
		self._textBox1.Location = System.Drawing.Point(154, 39)
		self._textBox1.Name = "textBox1"
		self._textBox1.Size = System.Drawing.Size(100, 20)
		self._textBox1.TabIndex = 0
		# 
		# textBox2
		# 
		self._textBox2.Location = System.Drawing.Point(154, 88)
		self._textBox2.Name = "textBox2"
		self._textBox2.Size = System.Drawing.Size(100, 20)
		self._textBox2.TabIndex = 1
		# 
		# button1
		# 
		self._button1.Location = System.Drawing.Point(154, 138)
		self._button1.Name = "button1"
		self._button1.Size = System.Drawing.Size(100, 23)
		self._button1.TabIndex = 2
		self._button1.Text = "Submit"
		self._button1.UseVisualStyleBackColor = True
		self._button1.Click += self.Button1Click
		# 
		# MainForm
		# 
		self.ClientSize = System.Drawing.Size(284, 207)
		self.Controls.Add(self._button1)
		self.Controls.Add(self._label2)
		self.Controls.Add(self._textBox2)
		self.Controls.Add(self._label1)
		self.Controls.Add(self._textBox1)
		self.Name = "MainForm"
		self.Text = "pythontest"
		self.ResumeLayout(False)
		self.PerformLayout()

	def Button1Click(self, sender, e):
		self.Close()

if __name__ == " __main__":
    form = MainForm()
    form.ShowDialog()
```

---

<div class="post-metadata">

**Author:** ![clement](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/clement/32/772979_2.png) [@clement](https://discourse.mcneel.com/u/clement)\
**Post date:** [May 17, 2015, 10:24pm UTC](https://discourse.mcneel.com/t/first-python-form-sharpdevelop/20276/2 "2015-05-17T22:24:30Z")

</div>

Hi Keith,

just some notes to make this work. Currently the form (the submit button) just returns Cancel. To change this you might add this to your button1 section:

```python
# button1
self._button1.DialogResult = System.Windows.Forms.DialogResult.OK

```

This will make your form return OK only when the submit button is pressed. Together with the dialog result added to your submit button, you can call your form like this and retrieve its textbox values from your form object if the result OK is returned:

```python
if __name__ == " __main__":
    form = MainForm()
    if (form.ShowDialog()) == System.Windows.Forms.DialogResult.OK:
        print(form._textBox1.Text)
        print(form._textBox2.Text)

```

Btw. some note: the underscore in front indicates usually a class “internal use”, which is now not fully correct anymore 🙂

One handy thing to consider is that when you enter something into your form, the entered content is still “there” even after you have closed and reopened the form. This is true as long as your form object is not disposed using `form.Dispose()`

btw. you might also define some default text for your textBox… fields using this syntax:

```python
self._textBox1.Text = "rhino"
self._textBox2.Text = "rocks"

```

- 

c.

---

<div class="post-metadata">

**Author:** ![KeithR](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/keithr/32/771243_2.png) [@KeithR](https://discourse.mcneel.com/u/KeithR)\
**Post date:** [May 18, 2015, 6:23am UTC](https://discourse.mcneel.com/t/first-python-form-sharpdevelop/20276/3 "2015-05-18T06:23:49Z")

</div>

Thanks for all your help Clement - will this Form also work on a Mac ?

Here is the now-working code as reference:

```
import System.Drawing
import System.Windows.Forms

from System.Drawing import *
from System.Windows.Forms import *

class MainForm(Form):
	def __init__ (self):
		self.InitializeComponent()
	
	def InitializeComponent(self):
		self._textBox1 = System.Windows.Forms.TextBox()
		self._label1 = System.Windows.Forms.Label()
		self._label2 = System.Windows.Forms.Label()
		self._textBox2 = System.Windows.Forms.TextBox()
		self._button1 = System.Windows.Forms.Button()
		self.SuspendLayout()
		# 
		# label1
		# 
		self._label1.Location = System.Drawing.Point(40, 39)
		self._label1.Name = "label1"
		self._label1.Size = System.Drawing.Size(100, 20)
		self._label1.TabIndex = 4
		self._label1.Text = "label1"
		# 
		# label2
		# 
		self._label2.Location = System.Drawing.Point(40, 88)
		self._label2.Name = "label2"
		self._label2.Size = System.Drawing.Size(100, 20)
		self._label2.TabIndex = 3
		self._label2.Text = "label2"
		# 
		# textBox1
		# 
		self._textBox1.Location = System.Drawing.Point(154, 39)
		self._textBox1.Name = "textBox1"
		self._textBox1.Size = System.Drawing.Size(100, 20)
		self._textBox1.TabIndex = 0
		# 
		# textBox2
		# 
		self._textBox2.Location = System.Drawing.Point(154, 88)
		self._textBox2.Name = "textBox2"
		self._textBox2.Size = System.Drawing.Size(100, 20)
		self._textBox2.TabIndex = 1
		# 
		# button1
		# 
		self._button1.Location = System.Drawing.Point(154, 138)
		self._button1.Name = "button1"
		self._button1.Size = System.Drawing.Size(100, 23)
		self._button1.TabIndex = 2
		self._button1.Text = "Submit"
		self._button1.UseVisualStyleBackColor = True
		self._button1.Click += self.Button1Click
		self._button1.DialogResult = System.Windows.Forms.DialogResult.OK
		# 
		# MainForm
		# 
		self.ClientSize = System.Drawing.Size(284, 207)
		self.Controls.Add(self._button1)
		self.Controls.Add(self._label2)
		self.Controls.Add(self._textBox2)
		self.Controls.Add(self._label1)
		self.Controls.Add(self._textBox1)
		self.Name = "MainForm"
		self.Text = "pythontest"
		self.ResumeLayout(False)
		self.PerformLayout()

	def save():
		key = self._textBox1.Text() 

	def Button1Click(self, sender, e):
		self.Close()

if __name__ == " __main__":
    form = MainForm()
    if (form.ShowDialog()) == System.Windows.Forms.DialogResult.OK:
        print(form._textBox1.Text)
        print(form._textBox2.Text)
```

---

<div class="post-metadata">

**Author:** ![clement](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/clement/32/772979_2.png) [@clement](https://discourse.mcneel.com/u/clement)\
**Post date:** [May 18, 2015, 11:08am UTC](https://discourse.mcneel.com/t/first-python-form-sharpdevelop/20276/4 "2015-05-18T11:08:28Z")

</div>

> [@KeithR](#):
>
> will this Form also work on a Mac ?

not shure, someone else owning a Mac may have to try out and report here…

- 

c.

---

<div class="post-metadata">

**Author:** ![Helvetosaur](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/helvetosaur/32/635974_2.png) [@Helvetosaur](https://discourse.mcneel.com/u/Helvetosaur)\
**Post date:** [May 18, 2015, 11:10am UTC](https://discourse.mcneel.com/t/first-python-form-sharpdevelop/20276/5 "2015-05-18T11:10:00Z")

</div>

I think virtually none of the WindowsForms stuff will work on Mac Rhino. You’ll have to wait until they implement [ETO](https://github.com/picoe/Eto)…

---

<div class="post-metadata">

**Author:** ![eric.bunn](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/eric.bunn/32/192528_2.png) [@eric.bunn](https://discourse.mcneel.com/u/eric.bunn)\
**Post date:** [February 10, 2020, 11:23am UTC](https://discourse.mcneel.com/t/first-python-form-sharpdevelop/20276/6 "2020-02-10T11:23:49Z")

</div>

How does one download and install a copy of SmartDevelop through GitHub? I see the files for SharpDevelop but no executable to launch the software.

Eric

---

<div class="post-metadata">

**Author:** ![djordje](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/djordje/32/747634_2.png) [@djordje](https://discourse.mcneel.com/u/djordje)\
**Post date:** [February 10, 2020, 1:01pm UTC](https://discourse.mcneel.com/t/first-python-form-sharpdevelop/20276/7 "2020-02-10T13:01:38Z")

</div>

Hi Eric,

> **[SharpDevelop](https://sourceforge.net/projects/sharpdevelop/)**
>
> Download SharpDevelop for free. A free IDE for C#, VB.NET, & Boo projects on Microsoft's .NET platform. SharpDevelop is the open-source IDE for the .NET platform. Write applications in languages including C#, VB.NET, F#, IronPython and IronRuby,...

---

<div class="post-metadata">

**Author:** ![eric.bunn](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/eric.bunn/32/192528_2.png) [@eric.bunn](https://discourse.mcneel.com/u/eric.bunn)\
**Post date:** [February 10, 2020, 1:13pm UTC](https://discourse.mcneel.com/t/first-python-form-sharpdevelop/20276/8 "2020-02-10T13:13:28Z")

</div>

Thanks.

---

<div class="post-metadata">

**Author:** ![eric.bunn](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/eric.bunn/32/192528_2.png) [@eric.bunn](https://discourse.mcneel.com/u/eric.bunn)\
**Post date:** [February 10, 2020, 2:34pm UTC](https://discourse.mcneel.com/t/first-python-form-sharpdevelop/20276/9 "2020-02-10T14:34:34Z")

</div>

Djordje,

Just installed and worked perfectly. Thank you again.

Eric

---

<div class="post-metadata">

**Author:** ![ivelin.peychev](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/ivelin.peychev/32/676038_2.png) [@ivelin.peychev](https://discourse.mcneel.com/u/ivelin.peychev)\
**Post date:** [February 10, 2020, 5:03pm UTC](https://discourse.mcneel.com/t/first-python-form-sharpdevelop/20276/10 "2020-02-10T17:03:18Z")

</div>

Make sure you download version 4 not 5, as 5 only supports C# not IronPython.

---

<div class="post-metadata">

**Author:** ![ivelin.peychev](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/ivelin.peychev/32/676038_2.png) [@ivelin.peychev](https://discourse.mcneel.com/u/ivelin.peychev)\
**Post date:** [February 10, 2020, 5:07pm UTC](https://discourse.mcneel.com/t/first-python-form-sharpdevelop/20276/11 "2020-02-10T17:07:19Z")

</div>

On that subject, @piac how plausible would it be to add ETO support for SharpDevelop gui designer, it’s open-source project?  
Currently it can detect WinForms inside any DLL and add it to the toolbox, but it doesn’t detect any forms inside ETO dll.

(feel free to split this into another thread if it requires a dedicated attention. :))

---

<div class="post-metadata">

**Author:** ![eric.bunn](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/eric.bunn/32/192528_2.png) [@eric.bunn](https://discourse.mcneel.com/u/eric.bunn)\
**Post date:** [February 10, 2020, 5:38pm UTC](https://discourse.mcneel.com/t/first-python-form-sharpdevelop/20276/12 "2020-02-10T17:38:55Z")

</div>

I downloaded version 4. I did read that 5 was for C+ only thank you.

---

<div class="post-metadata">

**Author:** ![eric.bunn](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/eric.bunn/32/192528_2.png) [@eric.bunn](https://discourse.mcneel.com/u/eric.bunn)\
**Post date:** [February 14, 2020, 3:31am UTC](https://discourse.mcneel.com/t/first-python-form-sharpdevelop/20276/13 "2020-02-14T03:31:12Z")

</div>

How does one run a sharpdevelop user form from outside of the module. I don’t want to have to paste all that code Into my main module. I’d like to keep it remote and access it from the outside.

---

<div class="post-metadata">

**Author:** ![ivelin.peychev](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/ivelin.peychev/32/676038_2.png) [@ivelin.peychev](https://discourse.mcneel.com/u/ivelin.peychev)\
**Post date:** [February 14, 2020, 8:54am UTC](https://discourse.mcneel.com/t/first-python-form-sharpdevelop/20276/14 "2020-02-14T08:54:49Z")

</div>

The generated code is a class. You can call it from another script, but you do need to add some code in there to call your module.

---

<div class="post-metadata">

**Author:** ![eric.bunn](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/eric.bunn/32/192528_2.png) [@eric.bunn](https://discourse.mcneel.com/u/eric.bunn)\
**Post date:** [February 14, 2020, 11:28am UTC](https://discourse.mcneel.com/t/first-python-form-sharpdevelop/20276/15 "2020-02-14T11:28:54Z")

</div>

Thank you Ivelin. So obvious and staring me right in the face. I posted this code into another module and it called the form:

#import the Userform Class  
from UserForm\_MB2 import GetUFData

form = GetUFData()  
if form.ShowDialog() == System.Windows.Forms.DialogResult.Cancel:  
print(form.\_num\_Ply)  
print(form.\_num\_Length)  
print(form.\_num\_Width)  
print(form.\_num\_Height)  
print(form.\_num\_HingeOff)  
print(form.\_num\_ClampOff)  
print(form.\_num\_NumTog)  
print(form.\_num\_NumHinges)  
print(form.\_cmb\_HoleType)  
print(form.\_num\_HoleD)
