Exception in Tkinter callback Traceback (most recent call last): File "D:\python\Lib\tkinter\__init__.py", line 1948, in __call__ return self.func(*args) ^^^^^^^^^^^^^^^^ File "C:\Users\13923\Desktop\2\primay.py", line 69, in check Home(self.window) File "C:\Users\13923\Desktop\2\primay.py", line 96, in __init__ self.readExcel() File "C:\Users\13923\Desktop\2\primay.py", line 103, in readExcel self.head = pd.read_excel("1.xlsx").columns.tolist() ^^^^^^^^^^^^^^^^^^^^^^^ File "D:\python\Lib\site-packages\pandas\io\excel\_base.py", line 478, in read_excel io = ExcelFile(io, storage_options=storage_options, engine=engine) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\python\Lib\site-packages\pandas\io\excel\_base.py", line 1496, in __init__ ext = inspect_excel_format( ^^^^^^^^^^^^^^^^^^^^^ File "D:\python\Lib\site-packages\pandas\io\excel\_base.py", line 1371, in inspect_excel_format with get_handle( ^^^^^^^^^^^ File "D:\python\Lib\site-packages\pandas\io\common.py", line 868, in get_handle handle = open(handle, ioargs.mode) ^^^^^^^^^^^^^^^^^^^^^^^^^ FileNotFoundError: [Errno 2] No such file or directory: '1.xlsx' Exception in Tkinter callback Traceback (most recent call last): File "D:\python\Lib\tkinter\__init__.py", line 1948, in __call__ return self.func(*args) ^^^^^^^^^^^^^^^^ File "C:\Users\13923\Desktop\2\primay.py", line 219, in add_student self.detail_window.show_save(self.all_student_list) ^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'Home' object has no attribute 'all_student_list'
时间: 2023-07-28 19:57:14 浏览: 194
这个错误有两个部分。第一个部分是由于在 `readExcel` 函数中使用了 Pandas 库中的 `read_excel` 函数读取 Excel 文件时出现了错误。您需要检查代码中 `1.xlsx` 文件的路径是否正确以及文件是否存在。另外,还需要检查您是否正确安装了 Pandas 库。
第二个部分是由于在 `Home` 类中没有名为 `all_student_list` 的属性,但在 `add_student` 函数中使用了它。您需要定义一个 `all_student_list` 属性或检查代码中是否有拼写错误或其他语法错误。
相关问题
Exception in Tkinter callback Traceback (most recent call last): File "D:\SOFT\Python3.11\Lib\tkinter\__init__.py", line 1948, in __call__
根据提供的引用内容,这段代码似乎是使用Python编写的一个图形用户界面(GUI)程序,使用的库是Tkinter。异常信息"Exception in Tkinter callback"表示在Tkinter回调函数中出现了异常。根据提供的引用,无法确定具体的异常原因和解决方法。建议检查代码中与回调函数相关的部分,并确保其正确性。可能需要仔细检查函数的调用方式、参数传递等问题。此外,还可以尝试使用调试器来定位并解决该异常。
Exception in Tkinter callback Traceback (most recent call last): File "D:\Python\Python313\Lib\tkinter\__init__.py", line 2068, in __call__ return self.func(*args) ~~~~~~~~~^^^^^^^ File "C:\Users\u\Desktop\rcglV1.py", line 236, in move_item if self.dragged_item: ^^^^^^^^^^^^^^^^^ AttributeError: 'ScheduleManager' object has no attribute 'dragged_item' Exception in Tkinter callback Traceback (most recent call last): File "D:\Python\Python313\Lib\tkinter\__init__.py", line 2068, in __call__ return self.func(*args) ~~~~~~~~~^^^^^^^ File "C:\Users\u\Desktop\rcglV1.py", line 236, in move_item if self.dragged_item: ^^^^^^^^^^^^^^^^^ AttributeError: 'ScheduleManager' object has no attribute 'dragged_item' Exception in Tkinter callback Traceback (most recent call last): File "D:\Python\Python313\Lib\tkinter\__init__.py", line 2068, in __call__ return self.func(*args) ~~~~~~~~~^^^^^^^ File "C:\Users\u\Desktop\rcglV1.py", line 236, in move_item if self.dragged_item: ^^^^^^^^^^^^^^^^^ AttributeError: 'ScheduleManager' object has no attribute 'dragged_item' Exception in Tkinter callback Traceback (most recent call last): File "D:\Python\Python313\Lib\tkinter\__init__.py", line 2068, in __call__ return self.func(*args) ~~~~~~~~~^^^^^^^ File "C:\Users\u\Desktop\rcglV1.py", line 236, in move_item if self.dragged_item: ^^^^^^^^^^^^^^^^^ AttributeError: 'ScheduleManager' object has no attribute 'dragged_item' Exception in Tkinter callback Traceback (most recent call last): File "D:\Python\Python313\Lib\tkinter\__init__.py", line 2068, in __call__ return self.func(*args) ~~~~~~~~~^^^^^^^ File "C:\Users\u\Desktop\rcglV1.py", line 230, in on_drag_end if self.dragged_item: ^^^^^^^^^^^^^^^^^ AttributeError: 'ScheduleManager' object has no attribute 'dragged_item'
从错误信息来看,在尝试访问 `self.dragged_item` 属性时发生了 `AttributeError` 错误,这是因为 `ScheduleManager` 类中并没有定义这个属性。而该属性是在拖拽功能的方法里使用的,具体来说是在 `on_tree_select` 方法中应该初始化这个属性,但是在代码中可能没有正确地初始化或者某些情况下未被设置。
根据提供的文档内容,可以看到确实存在 `on_tree_select` 方法来记录开始拖拽的项,但是可能存在以下几种情况导致这个问题:
1. **拖拽操作未触发**:`on_tree_select` 方法没有被执行,因此 `self.dragged_item` 没有被设置。
2. **属性初始化问题**:`self.dragged_item` 可能在类初始化的时候就应该被设为 `None`,但在 `__init__` 中并未看到它的初始化。
为了修复这个问题,可以在 `ScheduleManager` 类的构造函数 (`__init__`) 中增加对 `self.dragged_item` 的初始化:
```python
def __init__(self, master):
...
# 新增属性用于跟踪窗口是否最小化
self.minimized = False
# 新增属性用于跟踪正在拖拽的项目
self.dragged_item = None # 初始化 dragged_item
...
```
此外,还需要确保 `on_tree_select` 方法能够正常执行并且正确设置 `self.dragged_item`。你可以检查一下绑定事件是否正确以及是否有其它可能导致 `on_tree_select` 没有被调用的因素。
最后,考虑到异常处理,可以修改涉及 `self.dragged_item` 的地方,使其更健壮,比如:
```python
def on_drag_end(self, event):
"""当拖拽结束时调用此方法"""
if hasattr(self, 'dragged_item') and self.dragged_item:
self.dragged_item = None # 清除拖拽项
self.update_list() # 更新列表
def move_item(self, event):
"""移动项到新位置"""
if hasattr(self, 'dragged_item') and self.dragged_item:
target_y = event.y
target_item = self.tree.identify_row(target_y)
if target_item and target_item != self.dragged_item:
dragged_idx = next((i for i, sch in enumerate(self.schedules) if sch['id'] == self.dragged_item), None)
target_idx = next((i for i, sch in enumerate(self.schedules) if sch['id'] == target_item), None)
if dragged_idx is not None and target_idx is not None:
# 移动项
self.schedules.insert(target_idx, self.schedules.pop(dragged_idx))
# 更新显示
self.tree.selection_set(self.dragged_item)
self.tree.focus(self.dragged_item)
self.tree.see(self.dragged_item)
```
通过以上改动,可以减少由于 `self.dragged_item` 未定义而导致的错误。同时建议调试时加入一些打印语句或断点,以便更好地理解程序流并找到潜在的问题根源。
阅读全文
相关推荐

















