拖放按钮tkinter python [英] Drag and Drop button tkinter python

查看:26
本文介绍了拖放按钮tkinter python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新使用的tkinter在python上,我想开发一个程序,可以拖放一个按钮按下另一个…我会试着解释:我有一个按钮‘A’,它将创建一个新的按钮‘B’,我想将这个新按钮拖到另一个地方 有什么帮助吗 谢谢

推荐答案

tkinter.dnd模块,如suggestedbyj_4321在评论中。
以下是使用库执行您所说操作一些示例代码:

from tkinter import *
from tkinter.dnd import Tester as DragWindow, Icon as Dragable

# Make a root window and hide it, since we don't need it.
root = Tk()
root.withdraw()
# Make the actual main window, which can have dragable objects on.
main = DragWindow(root)

def make_btn():
    """Make a new test button."""
    # The functional part of the main window is the canvas.
    Dragable('B').attach(main.canvas)

# Make a button and bind it to our button creating function.
Button(main.top, text='A', command=make_btn).pack()
# Start the mainloop.
mainloop()

这篇关于拖放按钮tkinter python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆