拖放按钮 tkinter python
Drag and Drop button tkinter python
我是在 python 上使用 tkinter 的新手,我想开发一个程序,可以拖放一个按钮按下另一个按钮...我将尝试解释:我有按钮 'A' 将创建一个新按钮 'B' 我想将新按钮拖到另一个地方
任何帮助
谢谢
评论里的tkinter.dnd
module, as by 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 的新手,我想开发一个程序,可以拖放一个按钮按下另一个按钮...我将尝试解释:我有按钮 'A' 将创建一个新按钮 'B' 我想将新按钮拖到另一个地方 任何帮助 谢谢
评论里的tkinter.dnd
module, as
下面是一些示例代码,使用该库来执行您所说的操作:
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()