Getting Python error: AttributeError: 'tuple' object has no attribute 'Text'
Getting Python error: AttributeError: 'tuple' object has no attribute 'Text'
我会尽量写详细的。
我是一个名为 Virtual Forms 的工具的作者。它是一个 ActiveX 服务器控件。
目前,我只在 VBA、VB.NET 和 C# 中使用过它
现在我想在 windows 上从 Python 使用它。
它有效,但是,我卡在了一行代码上。
代码如下:
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=mydatabase;" \
"USER=imtheuser;" \
"PASSWORD=hereismypass;" \
"OPTION=3;"
#vf1.OpenVirtualFormDesigner()
vf1.ShowVirtualForm("VF2")
vf1.TextBox("VF2", "[customerid]").Text = "888"
所以我可以调用方法并将一些参数传递给这个控件。
该控件接受 VFFile、DatabaseType 和 ConnectionString 参数,因为它打开虚拟窗体,连接到 MySQL 数据库并显示数据。这是屏幕截图:
。
然后,在 VBA 中,我使用这行代码更改文本框中的文本:
vf1.TextBox("VF2", "[customerid]").Text = "888"
这是它在 VBA 中工作的屏幕截图:
。
但是当我从 Python 开始尝试时,我得到了这个错误:
C:\Users\WinPIS\venv\VFPython\Scripts\python.exe
C:/Users/WinPIS/PycharmProjects/VFPython/VFPythonFile.py
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'
Process finished with exit code 1
这仅适用于 windows。
如果您想尝试一下,您需要安装此下载中的虚拟表单控件的安装程序:
https://www.virtual-forms.com/sharing/Virtual%20Forms%20Framework2.0.0.31.zip
这是 VFFile:
https://www.virtual-forms.com/sharing/VFFilePython.vf
欢迎提出任何建议。
谢谢,
达沃
更新:
那个
print(dir(vf1))
给出这个:
['CLSID', 'CloseAllVirtualForms', 'CommandButton', 'ConnectDatabase', 'DisconnectDatabase', 'EditRefresh', 'EditState', 'EditStateChange', 'GridRefresh', 'OpenVirtualFormDesigner', 'SectorVisible', 'ShowAboutBox', 'ShowVirtualForm', 'SplashShow', 'Splashhide', 'TextBox', 'TriggerBeforeFormOpen', 'TriggerCommandButtonAction', 'TriggerCommandButtonClick', 'TriggerCommandButtonGroupChange', 'TriggerCommandButtonViewClick', 'TriggerEditAfterSave', 'TriggerEditBeforeSave', 'TriggerEditChange', 'TriggerFlexChange', 'TriggerGenerateID', 'TriggerMenuFunction', 'TriggerTextBoxChange', 'TriggerTextBoxCheck', 'TriggerTextBoxGotFocus', 'TriggerTextBoxInit', 'TriggerTextBoxLostFocus', 'TriggerTextBoxValidate', 'VFInternalCheck', 'VirtualForm', '_ApplyTypes_', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattr__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_get_good_object_', '_get_good_single_object_', '_oleobj_', '_prop_map_get_', '_prop_map_put_', 'coclass_clsid']
和
print(dir(vf1.TextBox("VF2", "[customerid]")))
给出这个:
['__add__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'count', 'index']
谢谢大家,
你的指导让我离答案更近了。
答案是,我需要在末尾包含 [0]。
所以错误在这一行:
vf1.TextBox("VF2", "[customerid]").Text = "888"
答案是在末尾加上[0]。这是有效的代码行:
vf1.TextBox("VF2", "[customerid]")[0].Text = "888"
再次感谢大家
我会尽量写详细的。
我是一个名为 Virtual Forms 的工具的作者。它是一个 ActiveX 服务器控件。
目前,我只在 VBA、VB.NET 和 C# 中使用过它 现在我想在 windows 上从 Python 使用它。 它有效,但是,我卡在了一行代码上。
代码如下:
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=mydatabase;" \
"USER=imtheuser;" \
"PASSWORD=hereismypass;" \
"OPTION=3;"
#vf1.OpenVirtualFormDesigner()
vf1.ShowVirtualForm("VF2")
vf1.TextBox("VF2", "[customerid]").Text = "888"
所以我可以调用方法并将一些参数传递给这个控件。
该控件接受 VFFile、DatabaseType 和 ConnectionString 参数,因为它打开虚拟窗体,连接到 MySQL 数据库并显示数据。这是屏幕截图:
。 然后,在 VBA 中,我使用这行代码更改文本框中的文本:
vf1.TextBox("VF2", "[customerid]").Text = "888"
这是它在 VBA 中工作的屏幕截图:
。
但是当我从 Python 开始尝试时,我得到了这个错误:
C:\Users\WinPIS\venv\VFPython\Scripts\python.exe
C:/Users/WinPIS/PycharmProjects/VFPython/VFPythonFile.py
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'
Process finished with exit code 1
这仅适用于 windows。
如果您想尝试一下,您需要安装此下载中的虚拟表单控件的安装程序:
https://www.virtual-forms.com/sharing/Virtual%20Forms%20Framework2.0.0.31.zip
这是 VFFile:
https://www.virtual-forms.com/sharing/VFFilePython.vf
欢迎提出任何建议。
谢谢,
达沃
更新:
那个
print(dir(vf1))
给出这个:
['CLSID', 'CloseAllVirtualForms', 'CommandButton', 'ConnectDatabase', 'DisconnectDatabase', 'EditRefresh', 'EditState', 'EditStateChange', 'GridRefresh', 'OpenVirtualFormDesigner', 'SectorVisible', 'ShowAboutBox', 'ShowVirtualForm', 'SplashShow', 'Splashhide', 'TextBox', 'TriggerBeforeFormOpen', 'TriggerCommandButtonAction', 'TriggerCommandButtonClick', 'TriggerCommandButtonGroupChange', 'TriggerCommandButtonViewClick', 'TriggerEditAfterSave', 'TriggerEditBeforeSave', 'TriggerEditChange', 'TriggerFlexChange', 'TriggerGenerateID', 'TriggerMenuFunction', 'TriggerTextBoxChange', 'TriggerTextBoxCheck', 'TriggerTextBoxGotFocus', 'TriggerTextBoxInit', 'TriggerTextBoxLostFocus', 'TriggerTextBoxValidate', 'VFInternalCheck', 'VirtualForm', '_ApplyTypes_', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattr__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_get_good_object_', '_get_good_single_object_', '_oleobj_', '_prop_map_get_', '_prop_map_put_', 'coclass_clsid']
和
print(dir(vf1.TextBox("VF2", "[customerid]")))
给出这个:
['__add__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'count', 'index']
谢谢大家,
你的指导让我离答案更近了。
答案是,我需要在末尾包含 [0]。
所以错误在这一行:
vf1.TextBox("VF2", "[customerid]").Text = "888"
答案是在末尾加上[0]。这是有效的代码行:
vf1.TextBox("VF2", "[customerid]")[0].Text = "888"
再次感谢大家