Skip to content
Advertisement

Python .NET WinForms – How to pass info from a textbox to a button click event

Before I get into my question, I am (self) learning how Python and the .NET CLR interact with each other. It has been a fun, yet, at times, a frustrating experience.

With that said, I am playing around on a .NET WinForm that should just simply pass data that is typed into a text box and display it via a message box. Learning how to do this should propel me into other means of passing data. This simple task seems to elude me and I can’t seem to find any good documentation on how tyo accomplish this. Has anyone attempted this? If so, I am willing to learn so if someone could point me in the right direction or give me a hint as to what I’ve done wrong?

PS – I have done some coding in C#.NET and VB.NET so the passing of the variables seems like it should be enough but apparently it isn’t.

JavaScript

Advertisement

Answer

txt is a local variable in __init__, meaning that you can’t access it from any other function. To fix it, make it an instance variable by attaching it to self (which refers to the instance itself):

JavaScript

and

JavaScript
Advertisement