鱼C论坛

 找回密码
 立即注册
查看: 7427|回复: 3

[已解决]请问tkinter或者ttk能不能像wxpython一样支持文件的拖放功能

[复制链接]
发表于 2016-8-28 20:37:37 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
wxpython可以支持文件拖放功能,但是tkinter没找到,请问有没有什么办法实现?或者是结合wxpython的这个功能也可以
最佳答案
2016-8-29 10:13:22
tkinter.dnd
  1. >>> import tkinter.dnd as dnd
  2. >>> help(dnd)
  3. Help on module tkinter.dnd in tkinter:

  4. NAME
  5.     tkinter.dnd - Drag-and-drop support for Tkinter.
复制代码


运行 dnd.test() 会有一个例子~
可以在 3个tk窗口之间拖动 icon标签。
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2016-8-29 10:13:22 | 显示全部楼层    本楼为最佳答案   
tkinter.dnd
  1. >>> import tkinter.dnd as dnd
  2. >>> help(dnd)
  3. Help on module tkinter.dnd in tkinter:

  4. NAME
  5.     tkinter.dnd - Drag-and-drop support for Tkinter.
复制代码


运行 dnd.test() 会有一个例子~
可以在 3个tk窗口之间拖动 icon标签。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2016-8-29 21:15:01 | 显示全部楼层

谢谢,我就想把文件拖到entry窗口,然后自动识别它的路径,这个功能可以实现吗?
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-5-30 16:56:28 | 显示全部楼层
windows可以用pip安装windnd库
可以用下面的代码测试
---------------------
import windnd
import tkinter
top = tkinter.Tk()
txt = tkinter.Text(top)
# 对文件的操作
def func(ls):
    txt.delete(0.,"end")
    for i in ls:
        txt.insert("end",i.decode("gbk")+'\n')
# windows 挂钩
windnd.hook_dropfiles(txt.winfo_id(),func)
txt.pack(side="top")
top.mainloop()
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2026-2-22 11:30

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表