|

楼主 |
发表于 2024-3-17 16:34:20
|
显示全部楼层
我现在写的是:
class WindowB(BaseWindow):
def __init__(self):
super().__init__()
self.textEdit_5 = QtWidgets.QTextEdit(parent=self)
# 其他初始化代码...
exclude_rules = {}
# 绑定按钮点击事件
self.pushButton_3.clicked.connect(lambda: self.start_thread('xls'))
def start_thread(self, file_type):
# 允许TextEdit_5编辑
self.textEdit_5.setReadOnly(False)
# 在 `start_thread` 方法中创建 MyThread 对象时,将 File_Path和self 作为参数传递给它:
thread = MyThread(file_type, self.File_Path, self, self.textEdit_5,
self.pushButton_11, self.pushButton_12)
thread.start()
class MyThread(threading.Thread):
# 在 MyThread 类中,修改 `__init__` 方法,接收File_Path和window,并将其存储为实例属性:
def __init__(self, file_type, file_path, windowB, textEdit_5, pushButton_11, pushButton_12):
super().__init__()
self.File_Type = file_type
self.File_Path = file_path
self.window = windowB
self.textEdit_5 = textEdit_5
self.pushButton_11 = pushButton_11
self.pushButton_12 = pushButton_12
def run(self):
file_path = os.path.join(self.File_Path, file_name)
Exclud_Book = xlrd.open_workbook(file_path)
self.textEdit_5.setReadOnly(False)
for sheet_name in Exclud_Book.sheet_names():
exclude_rows = []
exclude_rows_input = self.textEdit_5.toPlainText()
self.pushButton_11.setEnabled(True)
self.pushButton_12.setEnabled(True)
if exclude_rows_input:
if self.pushButton_11.clicked:
self.exclude_rows = [int(row) - 1 for row in exclude_rows_input.split(',')]
elif self.pushButton_12.clicked:
print('请重新录入行排除规则!')
continue
exclude_cols = []
exclude_cols_input = self.textEdit_5.toPlainText()
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)
但执行时会报错:
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 "D:\Python\pythonProject\20240317\xtt031703.py", line 1104, in run
self.exclude_rows = [int(row) - 1 for row in exclude_rows_input.split(',')]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Python\pythonProject\20240317\xtt031703.py", line 1104, in <listcomp>
self.exclude_rows = [int(row) - 1 for row in exclude_rows_input.split(',')]
^^^^^^^^
ValueError: invalid literal for int() with base 10: "尊敬的用户,欢迎您使用本系统!”
为什么报错会指向 "尊敬的用户,欢迎您使用本系统!”这一句啊,奇怪了? 请问要怎么处理? |
|