Name | tk-dragtool JSON |
Version |
1.1.4.1
JSON |
| download |
home_page | https://github.com/qfcy/tk-dragtool |
Summary | 提供用鼠标拖动、缩放tkinter控件工具的跨平台模块。A cross-platform module providing tools to dragand resize tkinter windows and widgets with the mouse. |
upload_time | 2024-10-25 09:35:17 |
maintainer | None |
docs_url | None |
author | qfcy |
requires_python | None |
license | None |
keywords |
tkinter
drag
tool
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
NAME 名称
tk_dragtool
DESCRIPTION 简介
提供用鼠标拖动、缩放tkinter控件工具的模块。
A module providing tools to drag and resize
tkinter window and widgets with the mouse.
FUNCTIONS 函数
bind_drag(tkwidget, dragger)
绑定拖曳事件。
tkwidget: 被拖动的控件或窗口,
dragger: 接收鼠标事件的控件,
调用bind_drag后,当鼠标拖动dragger时, tkwidget会被带着拖动, 但dragger
作为接收鼠标事件的控件, 位置不会改变。
Binds a drag event.
tkwidget: The widget or window to be dragged.
dragger: The widget that receives mouse events.
After calling bind_drag, when the mouse drags the dragger, the tkwidget will be dragged along, but the dragger, as the widget receiving mouse events, will not change its position.
bind_resize(tkwidget, dragger, anchor, min_w=0, min_h=0, move_dragger=True)
绑定缩放事件。
anchor: 缩放的方位, 取值为N,S,W,E,NW,NE,SW,SE,分别表示东、西、南、北。
min_w,min_h: 该方向tkwidget缩放的最小宽度(或高度)。
move_dragger: 缩放时是否移动dragger。
其他参数同bind_drag函数。
Binds a resize event.
anchor: The direction of resizing, with possible values N, S, W, E, NW, NE, SW, SE.
min_w, min_h: The minimum width (or height) for resizing the tkwidget in that direction.
move_dragger: Whether to move the dragger during resizing.
Other arguments are the same as for the bind_drag function.
draggable(tkwidget)
调用draggable(tkwidget) 使tkwidget可拖动。
tkwidget: 一个控件(Widget)或一个窗口(Wm)。
x 和 y: 只允许改变x坐标或y坐标。
Calling draggable(tkwidget) makes the tkwidget draggable.
tkwidget: A widget (Widget) or a window (Wm).
x and y: Allows changing only the x-coordinate or y-coordinate.
move(widget, x=None, y=None, width=None, height=None)
移动控件或窗口widget至指定坐标, 参数都为可选参数。
Moves the widget or window widget to the specified coordinates. All parameters are optional.
EXAMPLES 示例
.. code-block:: python
import tkinter as tk
from tk_dragtool import draggable
root=tk.Tk()
btn=tk.Button(root,text="Drag")
draggable(btn)
btn.place(x=0,y=0)
root.mainloop()
运行效果 Screenshot:
.. image:: https://img-blog.csdnimg.cn/47f8708a1eef42d591e922b8b0eb12d7.png
:alt: 效果图
更复杂的示例, 实现了8个缩放手柄的功能:
A more complex example implementing 8 scaling handles:
.. code-block:: python
btns=[] # 用btns列表存储创建的按钮
def add_button(func,anchor):
# func的作用是计算按钮新坐标
b=ttk.Button(root)
b._func=func
bind_resize(btn,b,anchor)
x,y=func()
b.place(x=x,y=y,width=size,height=size)
b.bind('<B1-Motion>',adjust_button,add='+')
b.bind('<B1-ButtonRelease>',adjust_button,add='+')
btns.append(b)
def adjust_button(event=None):
# 改变大小或拖动后,调整手柄位置
for b in btns:
x,y=b._func()
b.place(x=x,y=y)
root=tk.Tk()
root.title("Test")
root.geometry('500x350')
btn=ttk.Button(root,text="Button")
draggable(btn)
btn.bind('<B1-Motion>',adjust_button,add='+')
btn.bind('<B1-ButtonRelease>',adjust_button,add='+')
x1=20;y1=20;x2=220;y2=170;size=10
btn.place(x=x1,y=y1,width=x2-x1,height=y2-y1)
root.update()
# 创建各个手柄, 这里是控件缩放的算法
add_button(lambda:(btn.winfo_x()-size, btn.winfo_y()-size),
'nw')
add_button(lambda:(btn.winfo_x()+btn.winfo_width()//2,
btn.winfo_y()-size), 'n')
add_button(lambda:(btn.winfo_x()+btn.winfo_width(), btn.winfo_y()-size),
'ne')
add_button(lambda:(btn.winfo_x()+btn.winfo_width(),
btn.winfo_y()+btn.winfo_height()//2),'e')
add_button(lambda:(btn.winfo_x()+btn.winfo_width(),
btn.winfo_y()+btn.winfo_height()), 'se')
add_button(lambda:(btn.winfo_x()+btn.winfo_width()//2,
btn.winfo_y()+btn.winfo_height()),'s')
add_button(lambda:(btn.winfo_x()-size, btn.winfo_y()+btn.winfo_height()),
'sw')
add_button(lambda:(btn.winfo_x()-size,
btn.winfo_y()+btn.winfo_height()//2), 'w')
root.mainloop()
效果图 Screenshot:
.. image:: https://img-blog.csdnimg.cn/a64c54ff7c7148d7b943ff194dbc5292.gif
:alt: 更复杂示例的效果图
版本:1.1.4.1 (更新: 修复了文档中的小错误)
Version: 1.1.4.1 (Update: Fixed small mistakes in the documentation)
作者:``七分诚意 qq:3076711200``
作者CSDN主页: https://blog.csdn.net/qfcy\_/
Github: https://github.com/qfcy
Raw data
{
"_id": null,
"home_page": "https://github.com/qfcy/tk-dragtool",
"name": "tk-dragtool",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "tkinter, drag, tool",
"author": "qfcy",
"author_email": "3076711200@qq.com",
"download_url": "https://files.pythonhosted.org/packages/16/6c/679b67f298677972e2e572de0748009402e36ff9c95dc78dbfef36de357b/tk-dragtool-1.1.4.1.tar.gz",
"platform": null,
"description": "NAME \u540d\u79f0\r\n tk_dragtool\r\n\r\nDESCRIPTION \u7b80\u4ecb\r\n \u63d0\u4f9b\u7528\u9f20\u6807\u62d6\u52a8\u3001\u7f29\u653etkinter\u63a7\u4ef6\u5de5\u5177\u7684\u6a21\u5757\u3002\r\n A module providing tools to drag and resize\r\n tkinter window and widgets with the mouse.\r\n\r\nFUNCTIONS \u51fd\u6570\r\n bind_drag(tkwidget, dragger)\r\n \u7ed1\u5b9a\u62d6\u66f3\u4e8b\u4ef6\u3002\r\n tkwidget: \u88ab\u62d6\u52a8\u7684\u63a7\u4ef6\u6216\u7a97\u53e3,\r\n dragger: \u63a5\u6536\u9f20\u6807\u4e8b\u4ef6\u7684\u63a7\u4ef6,\r\n \u8c03\u7528bind_drag\u540e,\u5f53\u9f20\u6807\u62d6\u52a8dragger\u65f6, tkwidget\u4f1a\u88ab\u5e26\u7740\u62d6\u52a8, \u4f46dragger\r\n \u4f5c\u4e3a\u63a5\u6536\u9f20\u6807\u4e8b\u4ef6\u7684\u63a7\u4ef6, \u4f4d\u7f6e\u4e0d\u4f1a\u6539\u53d8\u3002\r\n Binds a drag event.\r\n tkwidget: The widget or window to be dragged.\r\n dragger: The widget that receives mouse events.\r\n After calling bind_drag, when the mouse drags the dragger, the tkwidget will be dragged along, but the dragger, as the widget receiving mouse events, will not change its position.\r\n\r\n bind_resize(tkwidget, dragger, anchor, min_w=0, min_h=0, move_dragger=True)\r\n \u7ed1\u5b9a\u7f29\u653e\u4e8b\u4ef6\u3002\r\n anchor: \u7f29\u653e\u7684\u65b9\u4f4d, \u53d6\u503c\u4e3aN,S,W,E,NW,NE,SW,SE,\u5206\u522b\u8868\u793a\u4e1c\u3001\u897f\u3001\u5357\u3001\u5317\u3002\r\n min_w,min_h: \u8be5\u65b9\u5411tkwidget\u7f29\u653e\u7684\u6700\u5c0f\u5bbd\u5ea6(\u6216\u9ad8\u5ea6)\u3002\r\n move_dragger: \u7f29\u653e\u65f6\u662f\u5426\u79fb\u52a8dragger\u3002\r\n \u5176\u4ed6\u53c2\u6570\u540cbind_drag\u51fd\u6570\u3002\r\n Binds a resize event.\r\n anchor: The direction of resizing, with possible values N, S, W, E, NW, NE, SW, SE.\r\n min_w, min_h: The minimum width (or height) for resizing the tkwidget in that direction.\r\n move_dragger: Whether to move the dragger during resizing.\r\n Other arguments are the same as for the bind_drag function.\r\n\r\n draggable(tkwidget)\r\n \u8c03\u7528draggable(tkwidget) \u4f7ftkwidget\u53ef\u62d6\u52a8\u3002\r\n tkwidget: \u4e00\u4e2a\u63a7\u4ef6(Widget)\u6216\u4e00\u4e2a\u7a97\u53e3(Wm)\u3002\r\n x \u548c y: \u53ea\u5141\u8bb8\u6539\u53d8x\u5750\u6807\u6216y\u5750\u6807\u3002\r\n Calling draggable(tkwidget) makes the tkwidget draggable.\r\n tkwidget: A widget (Widget) or a window (Wm).\r\n x and y: Allows changing only the x-coordinate or y-coordinate.\r\n\r\n move(widget, x=None, y=None, width=None, height=None)\r\n \u79fb\u52a8\u63a7\u4ef6\u6216\u7a97\u53e3widget\u81f3\u6307\u5b9a\u5750\u6807, \u53c2\u6570\u90fd\u4e3a\u53ef\u9009\u53c2\u6570\u3002\r\n Moves the widget or window widget to the specified coordinates. All parameters are optional.\r\n\r\nEXAMPLES \u793a\u4f8b\r\n\r\n.. code-block:: python\r\n\r\n import tkinter as tk\r\n from tk_dragtool import draggable\r\n \r\n root=tk.Tk()\r\n btn=tk.Button(root,text=\"Drag\")\r\n draggable(btn)\r\n btn.place(x=0,y=0)\r\n root.mainloop()\r\n\r\n\u8fd0\u884c\u6548\u679c Screenshot:\r\n\r\n.. image:: https://img-blog.csdnimg.cn/47f8708a1eef42d591e922b8b0eb12d7.png\r\n :alt: \u6548\u679c\u56fe\r\n\r\n\u66f4\u590d\u6742\u7684\u793a\u4f8b, \u5b9e\u73b0\u4e868\u4e2a\u7f29\u653e\u624b\u67c4\u7684\u529f\u80fd:\r\nA more complex example implementing 8 scaling handles:\r\n\r\n.. code-block:: python\r\n\r\n btns=[] # \u7528btns\u5217\u8868\u5b58\u50a8\u521b\u5efa\u7684\u6309\u94ae\r\n def add_button(func,anchor):\r\n # func\u7684\u4f5c\u7528\u662f\u8ba1\u7b97\u6309\u94ae\u65b0\u5750\u6807\r\n b=ttk.Button(root)\r\n b._func=func\r\n bind_resize(btn,b,anchor)\r\n x,y=func()\r\n b.place(x=x,y=y,width=size,height=size)\r\n b.bind('<B1-Motion>',adjust_button,add='+')\r\n\t\tb.bind('<B1-ButtonRelease>',adjust_button,add='+')\r\n btns.append(b)\r\n def adjust_button(event=None):\r\n # \u6539\u53d8\u5927\u5c0f\u6216\u62d6\u52a8\u540e,\u8c03\u6574\u624b\u67c4\u4f4d\u7f6e\r\n for b in btns:\r\n x,y=b._func()\r\n b.place(x=x,y=y)\r\n root=tk.Tk()\r\n root.title(\"Test\")\r\n root.geometry('500x350')\r\n btn=ttk.Button(root,text=\"Button\")\r\n draggable(btn)\r\n btn.bind('<B1-Motion>',adjust_button,add='+')\r\n\tbtn.bind('<B1-ButtonRelease>',adjust_button,add='+')\r\n x1=20;y1=20;x2=220;y2=170;size=10\r\n btn.place(x=x1,y=y1,width=x2-x1,height=y2-y1)\r\n root.update()\r\n # \u521b\u5efa\u5404\u4e2a\u624b\u67c4, \u8fd9\u91cc\u662f\u63a7\u4ef6\u7f29\u653e\u7684\u7b97\u6cd5\r\n add_button(lambda:(btn.winfo_x()-size, btn.winfo_y()-size),\r\n 'nw')\r\n add_button(lambda:(btn.winfo_x()+btn.winfo_width()//2,\r\n btn.winfo_y()-size), 'n')\r\n add_button(lambda:(btn.winfo_x()+btn.winfo_width(), btn.winfo_y()-size),\r\n 'ne')\r\n add_button(lambda:(btn.winfo_x()+btn.winfo_width(),\r\n btn.winfo_y()+btn.winfo_height()//2),'e')\r\n add_button(lambda:(btn.winfo_x()+btn.winfo_width(),\r\n btn.winfo_y()+btn.winfo_height()), 'se')\r\n add_button(lambda:(btn.winfo_x()+btn.winfo_width()//2,\r\n btn.winfo_y()+btn.winfo_height()),'s')\r\n add_button(lambda:(btn.winfo_x()-size, btn.winfo_y()+btn.winfo_height()),\r\n 'sw')\r\n add_button(lambda:(btn.winfo_x()-size,\r\n btn.winfo_y()+btn.winfo_height()//2), 'w')\r\n root.mainloop()\r\n\r\n\u6548\u679c\u56fe Screenshot:\r\n\r\n.. image:: https://img-blog.csdnimg.cn/a64c54ff7c7148d7b943ff194dbc5292.gif\r\n :alt: \u66f4\u590d\u6742\u793a\u4f8b\u7684\u6548\u679c\u56fe\r\n\r\n\u7248\u672c:1.1.4.1 (\u66f4\u65b0: \u4fee\u590d\u4e86\u6587\u6863\u4e2d\u7684\u5c0f\u9519\u8bef)\r\n\r\nVersion: 1.1.4.1 (Update: Fixed small mistakes in the documentation)\r\n\r\n\u4f5c\u8005:``\u4e03\u5206\u8bda\u610f qq:3076711200``\r\n\r\n\u4f5c\u8005CSDN\u4e3b\u9875: https://blog.csdn.net/qfcy\\_/\r\n\r\nGithub: https://github.com/qfcy\r\n",
"bugtrack_url": null,
"license": null,
"summary": "\u63d0\u4f9b\u7528\u9f20\u6807\u62d6\u52a8\u3001\u7f29\u653etkinter\u63a7\u4ef6\u5de5\u5177\u7684\u8de8\u5e73\u53f0\u6a21\u5757\u3002A cross-platform module providing tools to dragand resize tkinter windows and widgets with the mouse.",
"version": "1.1.4.1",
"project_urls": {
"Homepage": "https://github.com/qfcy/tk-dragtool"
},
"split_keywords": [
"tkinter",
" drag",
" tool"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "166c679b67f298677972e2e572de0748009402e36ff9c95dc78dbfef36de357b",
"md5": "53ee2f0861fd713652df8bc364b8e7b8",
"sha256": "2f00e5c03e8dd54d33c3b3e6ba2fb5f35b8c41c2e0a1477429635e7ee8bcb7d6"
},
"downloads": -1,
"filename": "tk-dragtool-1.1.4.1.tar.gz",
"has_sig": false,
"md5_digest": "53ee2f0861fd713652df8bc364b8e7b8",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 17372,
"upload_time": "2024-10-25T09:35:17",
"upload_time_iso_8601": "2024-10-25T09:35:17.827744Z",
"url": "https://files.pythonhosted.org/packages/16/6c/679b67f298677972e2e572de0748009402e36ff9c95dc78dbfef36de357b/tk-dragtool-1.1.4.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-25 09:35:17",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "qfcy",
"github_project": "tk-dragtool",
"github_not_found": true,
"lcname": "tk-dragtool"
}