Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>IronPython is a dynamic scripting language; it is interpreted at runtime from the script files themselves, rather than being compiled into an assembly. Since there is no compiled assembly, you cannot have an embedded resource. Here are two ways of adding an icon to a form in IronPython:</p> <p>First, you could include the icon as a loose file alongside the python scripts. You can then create the icon object by passing the icon filename to the System.Drawing.Icon constructor. Here is an example of this scenario, where the main python script and the icon are deployed in the same directory. The script uses the solution found <a href="https://stackoverflow.com/questions/606561/how-to-get-filename-of-the-main-module-in-python">here</a> to find the directory.</p> <pre><code>import clr clr.AddReference('System.Drawing') clr.AddReference('System.Windows.Forms') import os import __main__ from System.Drawing import Icon from System.Windows.Forms import Form scriptDirectory = os.path.dirname(__main__.__file__) iconFilename = os.path.join(scriptDirectory, 'test.ico') icon = Icon(iconFilename) form = Form() form.Icon = icon form.ShowDialog() </code></pre> <p>Alternatively, you can load an icon that is included as an embedded resource in a .NET assembly that is written in C#, for instance.</p> <pre><code>import clr clr.AddReference('System.Drawing') clr.AddReference('System.Windows.Forms') from System.Drawing import Icon from System.Reflection import Assembly from System.Windows.Forms import Form assembly = Assembly.LoadFile('C:\\code\\IconAssembly.dll') stream = assembly.GetManifestResourceStream('IconAssembly.Resources.test.ico') icon = Icon(stream) form = Form() form.Icon = icon form.ShowDialog() </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload