configs.process = int(self.edit_process.text()) AttributeError: 'MainWindow' object has no attribute 'edit_process'
时间: 2024-05-10 19:19:28 浏览: 14
这个错误提示是因为在你的 `MainWindow` 类中没有名为 `edit_process` 的属性。请检查你的代码,确保你正确地创建了该属性,并且你正在访问正确的对象。你可以在类的构造函数中创建 `edit_process` 属性,例如:
```python
class MainWindow(QtWidgets.QMainWindow):
def __init__(self):
super().__init__()
# 创建一个文本框
self.edit_process = QtWidgets.QLineEdit(self)
self.edit_process.setGeometry(50, 50, 200, 30)
```
在这个例子中,我们在构造函数中创建了一个 `QLineEdit` 对象,并将其赋值给了 `self.edit_process` 属性。你可以根据自己的需要修改属性的类型和参数。然后,在其他方法中,你就可以访问该属性并使用它,例如:
```python
configs.process = int(self.edit_process.text())
```
相关问题
def save_config(self): # configs.process = int(self.process_edit.text()) configs.path = self.path_edit.text() configs.Scalerfile_path = self.scaler_path_edit.text() configs.TDDIfile_path = self.tddi_path_edit.text() configs.UserDatafile_path = self.userdata_path_edit.text() with open("Config/configs.py", "w", encoding="utf-8") as f: f.write(f"# -*- coding: utf-8 -*-\n") # f.write(f"process = {configs.process}\n") f.write(f"path = \"{configs.path}\"\n") f.write(f"Scalerfile_path = \"{configs.Scalerfile_path}\"\n") f.write(f"TDDIfile_path = \"{configs.TDDIfile_path}\"\n") f.write(f"UserDatafile_path = \"{configs.UserDatafile_path}\"\n") time.sleep(0.5)这个怎么改为写入硬盘中
你可以将文件路径改为硬盘中的路径,例如:
```
with open("/mnt/data/Config/configs.py", "w", encoding="utf-8") as f:
```
这样就会将文件写入到硬盘的指定路径中。请根据你的实际情况修改路径。
AttributeError: 'Configs' object has no attribute 'mode_type'
这个错误意味着在你的代码中,一个名为 "Configs" 的对象没有名为 "mode_type" 的属性。当你尝试访问或使用这个属性时,Python 会引发 AttributeError 错误。
要解决这个问题,你可以检查以下几点:
1. 确保你创建了正确的 "Configs" 对象。检查你的代码,确认是否正确地初始化了这个对象,并为它设置了正确的属性。
2. 确认你的 "Configs" 类定义中是否包含了 "mode_type" 属性。可能是你在定义类时忘记添加这个属性,或者拼写错误。
3. 检查你在使用 "Configs" 对象时是否正确地访问了 "mode_type" 属性。确保你使用的语法是正确的,并且没有任何拼写错误或其他语法错误。
如果你能提供更多的代码或错误上下文,我可以给出更具体的帮助。