1
votes

This is probably a very noob question. I am trying to get some basic code from sharpdevelop into Pycharm. The code basically just draws a window and place some fields and buttons using Windows forms. I've set the interprter in Pycharm to be Ironpython. There seems to be something wrong with the import statements. When I run the following (Which is just a copy paste from code that is perfectly working in sharpdevelop):

import System.Drawing
import System.Windows.Forms

class MainForm(Form):
    def __init__(self):
    self.InitializeComponent()

def InitializeComponent(self):
    self._checkBox1 = System.Windows.Forms.CheckBox()
    self._comboBox1 = System.Windows.Forms.ComboBox()
    self._label1 = System.Windows.Forms.Label()
    #rest of code ...

I get the following message

ImportError: No module named Drawing

1

1 Answers

1
votes

You will need to add a reference to the DLLs. It's three lines:

import clr
clr.AddReference("System.Drawing")
clr.AddReference("System.Windows.Forms")

SharpDevelop takes care of adding the references in Program.py (the file that runs). It imports the MainForm class, instantiates it, and displays the form.

Since I am assuming this is the file you run, you will need to add the references within the same file.