我是在 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/