python - 拖放按钮 tkinter python

标签 python button tkinter drag-and-drop draggable

我是在 python 上使用 tkinter 的新手,我想开发一个程序,可以拖放一个按钮并按下另一个按钮...我将尝试解释:我有按钮“A”,它将创建一个新按钮“B”,我想将“新建”按钮拖到另一个位置 任何帮助 谢谢

最佳答案

tkinter.dnd模块,如suggested通过 j_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()

关于python - 拖放按钮 tkinter python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50803301/

相关文章:

Python Tkinter 如何使用网格为窗口着色

python - 我尝试从 picamera 获取 2 帧。为什么它的工作速度很慢?

Python sklearn 所有记录的余弦相似度循环

css - 十六进制颜色计算器 : change color for twitter bootstrap buttons

Javascript button.onclick 没有像我想象的那样运行

Javascript .length 和有类差异吗?

python - 有没有办法使 tkinter Frame 变灰(禁用)?

timer - 如何在 tkinter 中给定时间后运行函数?

python - xml.etree.ElementTree.ParseError : not well-formed (invalid token) due to "<" symbol in script

python - 解析具有未定义实体的 XHTML5