1

I have following example of code. I'm trying OpenFileDialog in Iron Python, but program just freezes instead of opening dialog window.

#!/usr/bin/ipy

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

from System.Windows.Forms import Application, Form, TextBox
from System.Windows.Forms import ToolBar, ToolBarButton, OpenFileDialog
from System.Windows.Forms import DialogResult, ScrollBars, DockStyle


class IForm(Form):

    def __init__(self):
        self.Text = "OpenDialog"

        toolbar = ToolBar()
        toolbar.Parent = self
        openb = ToolBarButton()


        self.textbox = TextBox()
        self.textbox.Parent = self
        self.textbox.Multiline = True
        self.textbox.ScrollBars = ScrollBars.Both
        self.textbox.WordWrap = False
        self.textbox.Parent = self
        self.textbox.Dock = DockStyle.Fill


        toolbar.Buttons.Add(openb)
        toolbar.ButtonClick += self.OnClicked


        self.CenterToScreen()

    def OnClicked(self, sender, event):
        dialog = OpenFileDialog()
        dialog.Filter = "C# files (*.cs)|*.cs"

        if dialog.ShowDialog(self) == DialogResult.OK:
            f = open(dialog.FileName)
            data = f.read()
            f.Close()
            self.textbox.Text = data


Application.Run(IForm())

The code is from http://zetcode.com/tutorials/ironpythontutorial/dialogs/

I'm using IronPython 2.7.5

What am I doing wrong ? And how I actually can OpenFileDialog and read the file?

Thanks in advance)

Alexander
  • 51
  • 2
  • 6

1 Answers1

2

So apparently all my troubles with IronPython were because I had several Python version installed on my computer. I deleted them all but IronPython, and then added IronPython to the Path manually. After that it's started working perfectly fine without crashes.

Alexander
  • 51
  • 2
  • 6