Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4590534
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:15:57+00:00 2026-05-21T22:15:57+00:00

I’m teaching an introductory class to programming and GUI development using Python, and have

  • 0

I’m teaching an introductory class to programming and GUI development using Python, and have found that the least overwhelming solution for students new to programming is to use Visual Studio for GUI development.

While the GUI development experience with C# and VB is pleasant, I couldn’t find a way to do the same with IronPython. I installed IronPython 2.7.1 which includes the Visual Studio tools, and created a WPF IronPython project.

I can use the WPF form designer just like VB and C#, however, I couldn’t find a convenient way (i.e., comprehensible to the students) in which the GUI elements could be accessed. For example, with VB, you can refer to elements based on their name and then you can modify properties within them. The best I could do with IronPython (which I don’t plan to show to the students) is the following:

import wpf

from System.Windows import Application, Window

class MyWindow(Window):
    def __init__(self):
        wpf.LoadComponent(self, 'WpfApplication3.xaml')

    def Button_Click(self, sender, e):
        #This is the only way I could find in which I can 
        #access an element and modify its properties
        self.Content.Children[1].Text += 'Hello World\n'


if __name__ == '__main__':
    Application().Run(MyWindow())

I noticed that the GUI elements do not get a name and Visual Studio crashes whenever I try to manually modify the XAML to name elements. Here is the generated XAML for a simple frame with a button and text area:

<Window 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Title="WpfApplication3" Height="300" Width="300"> 
    <Grid>
        <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="103,226,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click" />
        <TextBox Height="182" HorizontalAlignment="Left" Margin="24,21,0,0" VerticalAlignment="Top" Width="237" />
    </Grid>
</Window> 

Any assistance in making this easier on the students would be appreciated. I’m also open to other suggestions for Python GUI development which offer an experience similar to Visual Studio.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T22:15:57+00:00Added an answer on May 21, 2026 at 10:15 pm

    In IronPython 2.7 the wpf.LoadComponent method will wire up any properties with the same name as the XAML UI elements. If you are using IronPython 2.6 then you would need to use the code as suggested by WombatPM. So with IronPython 2.7 if you use the following XAML:

    <Window 
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
           Title="IronPyWpf" Height="300" Width="300">
        <Grid>
            <Button x:Name="button" Content="Button" Height="23" HorizontalAlignment="Left" Margin="103,226,0,0" VerticalAlignment="Top" Width="75"  />
            <TextBox x:Name="textbox" Height="182" HorizontalAlignment="Left" Margin="24,21,0,0" VerticalAlignment="Top" Width="237" />
        </Grid>
    </Window> 
    

    Then you can define two properties called button and textbox to access the UI elements:

    class MyWindow(Window):
        def __init__(self):
            wpf.LoadComponent(self, 'IronPyWpf.xaml')
            self._button.Content = 'My Button'
            self._textbox.Text = 'My Text'
    
        def get_button(self):
            return self._button
    
        def set_button(self, value):
            self._button = value
    
        button = property(get_button, set_button)
    
        def get_textbox(self):
            return self._textbox
    
        def set_textbox(self, value):
            self._textbox = value
    
        textbox = property(get_textbox, set_textbox)
    

    In fact it seems that you can simplify the code even further by removing the property definitions:

    class MyWindow(Window):
        def __init__(self):
            wpf.LoadComponent(self, 'IronPyWpf.xaml')
            self.button.Content = 'My Button'
            self.textbox.Text = 'My Text'
    

    Unfortunately Visual Studio seems to crash, as you have already seen, with a null reference exception when you try to edit the XAML and give the UI elements a name.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I have just tried to save a simple *.rtf file with some websites and
I have a bunch of posts stored in text files formatted in yaml/textile (from
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I am trying to loop through a bunch of documents I have to put

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.