Python Forum
Getting Python error: AttributeError: 'tuple' object has no attribute 'Text'
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Getting Python error: AttributeError: 'tuple' object has no attribute 'Text'
#1
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
Reply
#2
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.
Reply
#3
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.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Error: audioio has no attribute 'AudioOut' netwrok 3 592 Oct-22-2023, 05:53 PM
Last Post: netwrok
  getpass.getpass() results in AttributeError: module 'os' has no attribute 'O_NOCTTY' EarthAndMoon 4 718 Oct-03-2023, 02:00 PM
Last Post: deanhystad
  AttributeError: '_tkinter.tkapp' object has no attribute 'username' Konstantin23 4 1,529 Aug-04-2023, 12:41 PM
Last Post: Konstantin23
  Need help with 'str' object is not callable error. Fare 4 776 Jul-23-2023, 02:25 PM
Last Post: Fare
  Python: Regex is not good for re.search (AttributeError: 'NoneType' object has no att Melcu54 9 1,385 Jun-28-2023, 11:13 AM
Last Post: Melcu54
  Parallel processing - AttributeError: Can't get attribute 'sktimekmeans' Mohana1983 1 704 Jun-22-2023, 02:33 AM
Last Post: woooee
  Python: AttributeError: 'PageObject' object has no attribute 'extract_images' Melcu54 2 3,662 Jun-18-2023, 07:47 PM
Last Post: Melcu54
  Object attribute behavior different in 2 scripts db042190 1 685 Jun-14-2023, 12:37 PM
Last Post: deanhystad
  cx_oracle Error - AttributeError: 'function' object has no attribute 'cursor' birajdarmm 1 2,211 Apr-15-2023, 05:17 PM
Last Post: deanhystad
  Pandas AttributeError: 'DataFrame' object has no attribute 'concat' Sameer33 5 5,298 Feb-17-2023, 06:01 PM
Last Post: Sameer33

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020