我是在python上使用tkinter的新手,我想开发一个程序,可以按下按钮按下其他按钮...我会尝试解释:我有按钮' A&#39 ;这将创建一个新按钮' B'我想将“新建”按钮拖到另一个地方 任何帮助 谢谢
答案 0 :(得分:1)
tkinter.dnd
模块,suggested j_4321评论中的this
下面是一些使用该库执行所述操作的示例代码:
from tkinter import * #global tkinter import
from tkinter.dnd import Tester as Dragwindow, Icon as Dragable #import screen and object dragable classes
root=Tk() #make our root window
root.withdraw() #hide it since we don't need it
main=Dragwindow(root) #make our actual main window, it can have dragable objects on
def make_btn(): #make a new 'B' button
Dragable('B').attach(main.canvas) #make it and attach it to our window's functioning part, the canvas
Button(main.top, text='A', command=make_btn).pack() #make a button 'A' for our window
mainloop() #start the mainloop