|
发表于 2024-3-16 13:26:19
|
显示全部楼层
我现在写成这样:
self.pushButton_3.clicked.connect(self.start_thread)
def start_thread(self):
thread = MyThread()
thread.start()
class MyThread(threading.Thread):
def __init__(self, file_type):
super().__init__()
self.File_Type = file_type
def run(self):
if self.File_Type == 'xls':
file_name = "汇总表.xls"
# 拼接文件路径
file_path = os.path.join(self.File_Path, file_name)
Exclud_Book = xlrd.open_workbook(file_path)
else:
file_name = "汇总表.xlsx"
# 拼接文件路径
file_path = os.path.join(self.File_Path, file_name)
Exclud_Book = load_workbook(file_path)
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] = {'排除行': exclude_rows, '排除列': exclude_cols}
print(exclude_rules)
# 创建线程对象时传入File_Type参数
thread = MyThread('xls')
但是运行时报错:
Traceback (most recent call last):
File "D:\Python\pythonProject\20240316\xtt031601.py", line 1057, in start_thread
thread = MyThread()
^^^^^^^^^^
TypeError: MyThread.__init__() missing 1 required positional argument: 'file_type'
|
|