如何在 python gui 中为小部件创建拾取和放置选项?
How to create pick and place options for widgets in python gui?
我正在尝试在 python 中创建一个 GUI,其中输出是一个 window,它有按钮,我们可以选择这些按钮并将其放置在 [=21= 上的所需位置],同时该按钮也可供用户再次选择。
例子:
the image shows that the person can drag the buttons and the button is also available
在 python 中是否有任何选项可以做到这一点?我搜索了很多...我能够找到仅用于拖放的选项,但我无法找到任何用于克隆拖动的小部件的东西...我正在尝试创建一个类似于 https://studio.code.org/projects/applab/1NP-J2tjpgN7FADHvU7qc5dMFfxqCaEV0CrtKmHc4YM/edit
任何帮助都会很棒。谢谢!!
两个类似的Whosebug的答案解决了这个问题。
拖放 -
克隆(制作按钮的多个副本)- Bryan Oakley 在 中给出的答案
没有直接克隆小部件的方法,但 tkinter 为您提供了一种方法来确定小部件的父级、小部件的 class 以及小部件的所有配置值。此信息足以创建副本。
它看起来像这样:
def clone(widget):
parent = widget.nametowidget(widget.winfo_parent())
cls = widget.__class__
clone = cls(parent)
for key in widget.configure():
clone.configure({key: widget.cget(key)})
return clone
谢谢!!
我正在尝试在 python 中创建一个 GUI,其中输出是一个 window,它有按钮,我们可以选择这些按钮并将其放置在 [=21= 上的所需位置],同时该按钮也可供用户再次选择。 例子: the image shows that the person can drag the buttons and the button is also available
在 python 中是否有任何选项可以做到这一点?我搜索了很多...我能够找到仅用于拖放的选项,但我无法找到任何用于克隆拖动的小部件的东西...我正在尝试创建一个类似于 https://studio.code.org/projects/applab/1NP-J2tjpgN7FADHvU7qc5dMFfxqCaEV0CrtKmHc4YM/edit
任何帮助都会很棒。谢谢!!
两个类似的Whosebug的答案解决了这个问题。
拖放 -
克隆(制作按钮的多个副本)- Bryan Oakley 在
def clone(widget):
parent = widget.nametowidget(widget.winfo_parent())
cls = widget.__class__
clone = cls(parent)
for key in widget.configure():
clone.configure({key: widget.cget(key)})
return clone
谢谢!!