V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
rrZ2C
V2EX  ›  Python

大佬求救 python3 上我的 tkinterdnd2 写法有什么问题么

  •  
  •   rrZ2C · 139 天前 · 567 次点击
    这是一个创建于 139 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我问过 chatGpt 他一直跟我绕圈圈,google 的之后我总觉得代码没啥问题= =,秋指点打醒


    问题是我拽文件到 file_label 的时候光标有出现+(拽入功能应该是启用),不知道为什么没有打印



    import tkinter as tk

    from tkinterdnd2 import TkinterDnD, DND_FILES

    views:
    # 创建 drop
    self.file_label = tk.Label(self.master, text="Drop Files Here", relief=tk.SUNKEN,width=30, height=5)
    self.file_label.pack(pady=20)

    # 启用拖放功能
    self.file_label.drop_target_register(DND_FILES)
    self.file_label.dnd_bind('<<Drop>>', self.handle_drop)



    def handle_drop(self, event):
    # 检查是否为文件拖放事件
    print(" on handle_drop!")
    if event.data:
    file_path = event.data
    print(f"文件路径: {file_path}")
    self.handle_file(file_path)
    else:
    print("非文件拖放事件")



    -----------

    我之前用 windnd 是可以正常运作的,现在想迁移到 linux 接受拽入单独创建个区域

    -import windnd
    if __name__ == "__main__":
    - root = tk.Tk()
    + root = TkinterDnD.Tk()
    app = ConfigEditor(root)
    - windnd.hook_dropfiles(root , func=app.handle_drop)
    root.mainloop()
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1206 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 17:17 · PVG 01:17 · LAX 10:17 · JFK 13:17
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.