提交 c276bc58 编写于 作者: 小康2022

version 2.6.9.dev1

上级 9746028f
ChangeLog/更新日志
=================
[`2.6.9.dev0`] -2023-08-06
--------------------------
[`2.6.9.dev1`] - 2023-08-08
---------------------------
### Added/新增
- [X] Added new widget switch (`Switch`)
新增控件开关(`Switch`
- [X] Added widget Tip (`ToolTip`) and all virtual widgets added the parameter `tooltip`
新增控件提示框(`ToolTip`),且所有虚拟控件新增参数 `tooltip`
- [X] Added constants `DURATION``TOOLTIP_FG``TOOLTIP_BG``TOOLTIP_HIGNLIGHT_THICKNESS` and `TOOLTIP_HIGNLIGHT_BACKGROUND`
新增常量 `DURATION``TOOLTIP_FG``TOOLTIP_BG``TOOLTIP_HIGNLIGHT_THICKNESS``TOOLTIP_HIGNLIGHT_BACKGROUND`
- [X] Added constants `DURATION``TOOLTIP_FG``TOOLTIP_BG``TOOLTIP_HIGNLIGHT_THICKNESS``TOOLTIP_HIGNLIGHT_BACKGROUND``COLOR_SWITCH_ON``COLOR_SWITCH_OFF``SWITCH_WIDTH``SWITCH_HEIGHT``SWITCH_RADIUS` and `SWITCH_ANIMATION_MS`
新增常量 `DURATION``TOOLTIP_FG``TOOLTIP_BG``TOOLTIP_HIGNLIGHT_THICKNESS``TOOLTIP_HIGNLIGHT_BACKGROUND``COLOR_SWITCH_ON``COLOR_SWITCH_OFF``SWITCH_WIDTH``SWITCH_HEIGHT``SWITCH_RADIUS``SWITCH_ANIMATION_MS`
### Fixed/修复
- [X] Fixed an issue where the text class widget called method `clear` was invalid
修复了文本类控件调用方法 `clear` 无效的问题
- [X] Fixed an issue where the class `Animation` automatically determined the parent widget of the widget to be moved
修复了类 `Animation` 自动确定待移动控件的父控件时出现错误的问题
### Changed/变更
- [X] The positional parameter `length` of class `CheckButton` was renamed `height`
`CheckButton` 的位置参数 `length` 更名为 `height`
### Optimized/优化
- [X] Optimized the method `wm_geometry` of class `Tk` to accommodate some specially formatted parameters
......
......@@ -9,8 +9,8 @@ The `tkintertools` module is an auxiliary module of the `tkinter` module
[![Version](https://img.shields.io/pypi/v/tkintertools?label=Version)](.)
[![License](https://img.shields.io/pypi/l/tkintertools?label=License)](LICENSE.txt)
[![ChangeLog](https://img.shields.io/badge/ChangeLog-2023/08/06-orange)](CHANGELOG.md)
[![ToDo](https://img.shields.io/badge/ToDo-15-yellow)](TODO.md)
[![ChangeLog](https://img.shields.io/badge/ChangeLog-2023/08/08-orange)](CHANGELOG.md)
[![ToDo](https://img.shields.io/badge/ToDo-14-yellow)](TODO.md)
[![Size](https://img.shields.io/github/languages/code-size/Xiaokang2022/tkintertools?label=Size)](tkintertools)
[![Wiki](https://img.shields.io/badge/Wiki-14-purple)](https://github.com/Xiaokang2022/tkintertools/wiki)\
[![Downloads](https://img.shields.io/pypi/dm/tkintertools?label=Downloads&logo=pypi)](https://pypistats.org/packages/tkintertools)
......@@ -40,15 +40,15 @@ pip install tkintertools==2.6.8
### Development Version/开发版本
* Version/最新版本 : `2.6.9.dev0` (第 1 个预发布版本)
* Release/发布日期 : 2023/08/06 (UTC+08)
* Version/最新版本 : `2.6.9.dev1` (第 2 个预发布版本)
* Release/发布日期 : 2023/08/08 (UTC+08)
这个是我正在开发的版本,可能有新功能,bug 可能会比较多,但也可能会比原来的版本更加稳定。开发版没有经过多操作系统的测试,仅能保证在 Windows 系统下运行所有功能,在其他的操作系统上,可能有部分功能无法正常运行。大家可以在 Issues 中提出一些建议,我可能会适当采纳一些并在开发版本中更改或实现。
**PIP Cmd/安装命令:**
```
pip install tkintertools==2.6.9.dev0
pip install tkintertools==2.6.9.dev1
```
> **Warning**
......@@ -77,25 +77,31 @@ News/最新功能👇
### Release Notes/版本说明
**最新版本: `tkintertools-v2.6.9.dev0`**
**最新版本: `tkintertools-v2.6.9.dev1`**
> **Note**
> tkintertools 的介绍、使用教程和开发文档均在 [Wiki](https://github.com/Xiaokang2022/tkintertools/wiki) 中,大家可前往查阅
下面是本次开发版本(`v2.6.8` -> `v2.6.9.dev0`)的更新内容条目:
下面是本次开发版本(`v2.6.8` -> `v2.6.9.dev1`)的更新内容条目:
- [X] Added new widget switch (`Switch`)
新增控件开关(`Switch`
- [X] Added widget Tip (`ToolTip`) and all virtual widgets added the parameter `tooltip`
新增控件提示框(`ToolTip`),且所有虚拟控件新增参数 `tooltip`
- [X] Added constants `DURATION``TOOLTIP_FG``TOOLTIP_BG``TOOLTIP_HIGNLIGHT_THICKNESS` and `TOOLTIP_HIGNLIGHT_BACKGROUND`
新增常量 `DURATION``TOOLTIP_FG``TOOLTIP_BG``TOOLTIP_HIGNLIGHT_THICKNESS``TOOLTIP_HIGNLIGHT_BACKGROUND`
- [X] Added constants `DURATION``TOOLTIP_FG``TOOLTIP_BG``TOOLTIP_HIGNLIGHT_THICKNESS``TOOLTIP_HIGNLIGHT_BACKGROUND``COLOR_SWITCH_ON``COLOR_SWITCH_OFF``SWITCH_WIDTH``SWITCH_HEIGHT``SWITCH_RADIUS` and `SWITCH_ANIMATION_MS`
新增常量 `DURATION``TOOLTIP_FG``TOOLTIP_BG``TOOLTIP_HIGNLIGHT_THICKNESS``TOOLTIP_HIGNLIGHT_BACKGROUND``COLOR_SWITCH_ON``COLOR_SWITCH_OFF``SWITCH_WIDTH``SWITCH_HEIGHT``SWITCH_RADIUS``SWITCH_ANIMATION_MS`
- [X] Fixed an issue where the text class widget called method `clear` was invalid
修复了文本类控件调用方法 `clear` 无效的问题
- [X] Fixed an issue where the class `Animation` automatically determined the parent widget of the widget to be moved
修复了类 `Animation` 自动确定待移动控件的父控件时出现错误的问题
- [X] The positional parameter `length` of class `CheckButton` was renamed `height`
`CheckButton` 的位置参数 `length` 更名为 `height`
- [X] Optimized the method `wm_geometry` of class `Tk` to accommodate some specially formatted parameters
优化了类 `Tk` 的方法 `wm_geometry` 以适应某些特殊格式的参数
### Template Demo/模板演示
下面是一个主要新功能的示例程序,当按照示例代码方式给虚拟控件传入一个名为 `tooltip` 的参数之后,便可以让这个控件拥有提示框
下面是一个主要新功能的示例程序,即新增控件:开关!这个控件可以调整长宽、颜色、以及圆角的大小!
下面是示例程序的效果图(运行环境为 Windows11-Python3.11.4):
......@@ -106,8 +112,9 @@ News/最新功能👇
```python
# 此处只展示核心代码
tip = tkt.ToolTip('模块介绍\nToolTip 测试')
tkt.Button(canvas, 10, 660, 200, 50, text='Doc', tooltip=tip)
tkt.Switch(canvas, 540, 420) # 默认样式
tkt.Switch(canvas, 610, 420, radius=4, default=True) # 圆角半径 4 像素,默认开
tkt.Switch(canvas, 680, 420, radius=0) # 无圆角
```
</details>
......
......@@ -29,23 +29,20 @@ TODO/待办
2. [ ] Perfection and optimization of zoom function
对缩放功能的完善和优化
3. [ ] Try adding a new widget: `Switch`
尝试新增控件:开关 (`Switch`)
4. [ ] Try adding support for some MarkDown syntax
3. [ ] Try adding support for some MarkDown syntax
尝试增加对部分 Markdown 语法的支持
5. [ ] Try adding a new pattern of no progress to the `Progressbar` widget
4. [ ] Try adding a new pattern of no progress to the `Progressbar` widget
尝试为进度条控件增加无进度的新模式
6. [ ] Implement symmetry in 3D modules
5. [ ] Implement symmetry in 3D modules
实现 3D 模块中的对称功能
7. [ ] Enhanced projection functionality in 3D modules
6. [ ] Enhanced projection functionality in 3D modules
增强 3D 模块中的投影功能
8. [ ] Add more 3D spatial geometry classes
7. [ ] Add more 3D spatial geometry classes
增加更多 3D 空间几何体类
9. [ ] Add lights and achieve simple light and shadow renderings
8. [ ] Add lights and achieve simple light and shadow renderings
添加光源,并实现简单的光影渲染的效果
news.png

110.0 KB | W: | H:

news.png

30.4 KB | W: | H:

news.png
news.png
news.png
news.png
  • 2-up
  • Swipe
  • Onion skin
......@@ -26,9 +26,9 @@ Provides
Contents
--------
* Container Widgets: `Tk`, `Toplevel`, `Canvas`
* Virtual Canvas Widgets: `Label`, `Button`, `CheckButton`, `Entry`, `Text`, `Progressbar`
* Tool Classes: `PhotoImage`, `ToolTip`, `Singleton`, `Animation`
* Virtual Canvas Widgets: `Label`, `Button`, `CheckButton`, `Entry`, `Text`, `Progressbar`,`ToolTip`, `Switch`
* Tool Functions: `move`, `text`, `color`, `askfont`, `SetProcessDpiAwareness`
* Tool Classes: `PhotoImage`, `Singleton`, `Animation`
* Tool Submodules: `tool_3d`
More
......@@ -48,14 +48,14 @@ from .__main__ import *
from .constants import *
__author__ = 'Xiaokang2022<2951256653@qq.com>'
__version__ = '2.6.9.dev0'
__version__ = '2.6.9.dev1'
__all__ = [
# Container Widgets
'Tk', 'Toplevel', 'Canvas',
# Virtual Canvas Widgets
'Label', 'Button', 'CheckButton', 'Entry', 'Text', 'Progressbar',
'Label', 'Button', 'CheckButton', 'Entry', 'Text', 'Progressbar', 'ToolTip', 'Switch',
# Tool Classes
'PhotoImage', 'ToolTip', 'Singleton', 'Animation',
'PhotoImage', 'Singleton', 'Animation',
# Tool Functions
'move', 'text', 'color', 'askfont', 'SetProcessDpiAwareness',
] + all_constants
......@@ -175,6 +175,15 @@ class Toplevel(tkinter.Toplevel, Tk):
self.focus_set() # 把焦点转移到该子窗口上来
class CombinedItem(list):
""" 画布元素组合体 """
def __init__(self, *args): # type: (int) -> None
if not all(map(lambda _: isinstance(_, int), args)):
raise TypeError('Not all elements are of type _CanvasItemId')
list.__init__(self, args)
class Canvas(tkinter.Canvas):
""" 画布容器类 """
......@@ -987,7 +996,7 @@ class CheckButton(Button):
canvas, # type: Canvas
x, # type: int
y, # type: int
length, # type: int
height, # type: int
*,
radius=RADIUS, # type: float
text='', # type: str
......@@ -1001,14 +1010,14 @@ class CheckButton(Button):
color_outline=COLOR_BUTTON_OUTLINE # type: tuple[str, str, str]
): # type: (...) -> None
Button.__init__(
self, canvas, x, y, length, length, radius=radius, borderwidth=borderwidth, image=image,
self, canvas, x, y, height, height, radius=radius, borderwidth=borderwidth, image=image,
tooltip=tooltip, color_text=color_text, color_fill=color_fill, color_outline=color_outline)
if justify == 'right':
self._text = canvas.create_text(
x+1.25*length, y+length/2, text=text, anchor='w')
x+1.25*height, y+height/2, text=text, anchor='w')
else:
self._text = canvas.create_text(
x-0.25*length, y+length/2, text=text, anchor='e')
x-0.25*height, y+height/2, text=text, anchor='e')
self.command = lambda: self.set(not bool(self.value))
if value:
self.command()
......@@ -1311,6 +1320,85 @@ class Progressbar(BaseWidget):
self.configure(text='%.2f%%' % (percentage * 100))
class Switch:
""" 开关 """
def __init__(
self,
canvas, # type: Canvas
x, # type: int
y, # type: int
width=SWITCH_WIDTH, # type: int
height=SWITCH_HEIGHT, # type: int
*,
radius=SWITCH_RADIUS, # type: float
borderwidth=BORDERWIDTH, # type: int
tooltip=None, # type: ToolTip | None
color_fill=COLOR_SWITCH_OFF, # type: tuple[str, str, str]
color_outline=COLOR_BUTTON_OUTLINE, # type: tuple[str, str, str]
default=False, # type: bool
on=None, # type: Callable | None
off=None, # type: Callable | None
): # type: (...) -> None
"""
`canvas`: 父画布控件 \
`x`: 横坐标 \
`y`: 纵坐标 \
`width`: 宽度 \
`height`: 高度 \
`radius`: 圆角半径 \
`borderwidth`: 边框宽度 \
`tooltip`: 提示框 \
`color_fill`: 内部颜色 \
`color_outline`: 边框颜色 \
`default`: 默认值 \
`on`: 转换到开时触发的回调函数 \
`off`: 转换到关时触发的回调函数
"""
self.value = default
self.width = height * 2 if width < height * 2 else width
self.height = height
self.on = on
self.off = off
self.outside = Button(
canvas, x, y, self.width, height, radius=radius, borderwidth=borderwidth,
tooltip=tooltip, color_fill=color_fill, color_outline=color_outline,
command=lambda self=self: self.set(not self.value))
spcaing = height * 2 / 15
self.inside = Label(
canvas, x+spcaing, y+spcaing, height-spcaing*2, height-spcaing*2, radius=radius,
borderwidth=borderwidth, color_outline=('#333',)*3, color_fill=('black',)*3)
if self.value is True:
self._animate(0)
def _animate(self, ms=SWITCH_ANIMATION_MS): # type: (int) -> None
""" 移动动画 """
if self.value:
key = 1
self.outside.configure(
color_fill=COLOR_SWITCH_ON, color_outline=COLOR_SWITCH_ON)
else:
key = -1
self.outside.configure(
color_fill=COLOR_SWITCH_OFF, color_outline=COLOR_BUTTON_OUTLINE)
self.outside.state()
Animation(self.inside, ms, fps=90, control=(math.sin, 0, math.pi),
translation=(key*(self.width-self.height)*self.inside.master.rx, 0)).run()
def get(self): # type: () -> bool
""" 返回状态 """
return self.value
def set(self, value): # type: (bool) -> None
""" 设定状态 """
self.value = value
if self.value and self.on is not None:
self.on()
if not self.value and self.off is not None:
self.off()
self._animate()
class ToolTip:
""" 提示框 """
......@@ -1528,8 +1616,8 @@ class Animation:
`loop`: 是否循环播放动画,默认不循环,循环时参数 stop 失效
"""
self.widget = widget
self.master = canvas if isinstance(widget, int) else widget.master if isinstance(
widget, tkinter.Widget) else widget
self.master = canvas if isinstance(widget, int) else widget if isinstance(
widget, tkinter.Widget) else widget.master
self.start = start
self.step = step
self.stop = stop
......
......@@ -36,6 +36,12 @@ COLOR_NONE = '', '', '', ''
COLOR_BAR = '#E1E1E1', '#06b025'
""" Default progress bar color """
COLOR_SWITCH_ON = '#288CDB', '#3E98DF', '#4884B4', '#E0E0E0'
""" Default color when `Switch` is on """
COLOR_SWITCH_OFF = COLOR_BUTTON_FILL
""" Default color when `Switch` is off """
### Other constants ###
......@@ -83,6 +89,18 @@ TOOLTIP_HIGNLIGHT_THICKNESS = 1
TOOLTIP_HIGNLIGHT_BACKGROUND = 'black'
""" Default ToolTip highlightbackground """
SWITCH_WIDTH = 0
""" Default Switch width """
SWITCH_HEIGHT = 30
""" Default Switch height """
SWITCH_RADIUS = float('inf')
""" Default Switch radius """
SWITCH_ANIMATION_MS = 250
""" Default animation duration of the Switch """
### 3D constants ###
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册