|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
现有如下代码:
self.textEdit_5.setReadOnly(True)
按钮点击:
self.pushButton_3.clicked.connect(lambda: self.start_thread('xls'))
然后开启线程:
def start_thread(self, file_type):
thread = MyThread(file_type, self.File_Path) # 将 File_Path 作为参数传递给 MyThread
thread.start()
class MyThread(threading.Thread):
def __init__(self, file_type, file_path): # 接收 File_Path 参数并存储为实例属性
super().__init__()
self.File_Type = file_type
self.File_Path = file_path
def run(self):
if self.File_Type == 'xls':
file_name = "123.xls"
# 拼接文件路径
file_path = os.path.join(self.File_Path, file_name)
Exclud_Book = xlrd.open_workbook(file_path)
else:
file_name = "123.xlsx"
# 拼接文件路径
file_path = os.path.join(self.File_Path, file_name)
Exclud_Book = load_workbook(file_path)
此时我打开self.textEdit_5想录入数据:
self.textEdit_5.setReadOnly(False)
for sheet_name in Exclud_Book.sheet_names():
exclude_rows_input = input()
if exclude_rows_input:
self.exclude_rows = [int(row) - 1 for row in exclude_rows_input.split(',')]
exclude_cols_input = input()
if exclude_cols_input:
exclude_cols = [convert_position(col) for col in exclude_cols_input.split(',')]
exclude_rules[sheet_name] = {'1': exclude_rows, '2': exclude_cols}
print(exclude_rules)
然后就报错:
Exception in thread Thread-1:
Traceback (most recent call last):
File "D:\Tools\Python\Lib\threading.py", line 1045, in _bootstrap_inner
self.run()
File "C:\Users\ynyxs\Desktop\20240316\xtt031600.py", line 1080, in run
self.textEdit_5.setReadOnly(False)
^^^^^^^^^^^^^^^
AttributeError: 'MyThread' object has no attribute 'textEdit_5'
请问是什么原因?
|
|