Python Forum

Full Version: Getting Python error: AttributeError: 'tuple' object has no attribute 'Text'
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello guys,
I have a simple challenge for you.

I'm the author of a tool called Virtual Forms. It is an ActiveX server control.
For now, we have only used it from VBA, VB.NET & C#
Now my colleagues asked me if we could use it from Python on windows.
It works, but, because I'm also not a Python expert I got stuck on one line of code.

Here is the code that works:
import win32com.client as win32

vf1 = win32.gencache.EnsureDispatch('VirtualForm2.VirtualForm')

vf1.VFFile = r"C:\Users\WinPIS\Desktop\VFPython\VFFilePython.vf"

vf1.DatabaseType = 2

vf1.ConnectionString = r"DRIVER={MySQL ODBC 5.3 Unicode Driver};" \
                       "Port=3306;" \
                       "SERVER=myserver;" \
                       "DATABASE=mydb;" \
                       "USER=myusr;" \
                       "PASSWORD=mypass;" \
                       "OPTION=3;"

#vf1.OpenVirtualFormDesigner()

vf1.ShowVirtualForm("VF2")
As we can see, we can call methods and pass some parameters to this control.
The control accepts the VFFile, DatabaseType and the ConnectionString parameter, because when we run the line with code:

vf1.ShowVirtualForm("VF2")
it opens the Virtual Form, connect to the MySQL database and displays the data. Here is the screenshot:

[Image: VirtualForm2_2018-07-26_16-14-49.png]

Then, for example, in VBA I use this line of code to change the text that is in a textbox:

vf1.TextBox("VF2", "[customerid]").Text = "888"
And here is the screenshot that it works in VBA:

[Image: VirtualForm2_2018-07-26_16-30-00.png]

But when I try it from Python I got this error:

Error:
Traceback (most recent call last): File "C:/Users/WinPIS/PycharmProjects/VFPython/VFPythonFile.py", line 20, in <module> vf1.TextBox("VF2", "[customerid]").Text = "888" AttributeError: 'tuple' object has no attribute 'Text'
This only works in windows.
If you want to try it out you will need to install the setup for this Virtual Forms control that is in this download:
https://www.virtual-forms.com/sharing/Vi...0.0.31.zip

And here is the VFFile:
https://www.virtual-forms.com/sharing/VFFilePython.vf

Any suggestion is welcome.
Thanks,
Davor
A tuple is a sequence of immutable Python objects. Tuples are sequences, just like lists. The differences between tuples and lists are, the tuples cannot be changed unlike lists and tuples use parentheses, whereas lists use square brackets. I am also new to Python so I might be on the wrong track but maybe vf1 should not be of type tuple.
The error means that vf1.TextBox("VF2", "[customerid]") returns tuple. You can try
vf1.TextBox("VF2", "[customerid]")[0].Text = "888"
and see what the result will be.

Note that this is just a blind guess, I didn't install anything yet.
You can also play with iterating over what vf1.TextBox("VF2", "[customerid]") returns and print/check number of elements/ type of the objects, etc. Also as an author you should know what TextBox("VF2", "[customerid]") returns.