TinUISheet
TinUI的高级表格控件。
使用
TinUISheet类
TinUISheet(
ui:BasicTinUI, pos:tuple, width=300, height=300, minwidth=100, maxwidth=300,
font=('微软雅黑', 12),
fg='black', bg='white', itemfg='#1a1a1a', itembg='#f9f9f9', headbg='#f0f0f0',
itemactivefg='#191919', itemactivebg='#f0f0f0',
itemonfg='#191919', itemonbg='#e0e0e0',
scrollcolor='#8a8a8a',
headfont=('微软雅黑', 14),
anchor='nw'
)
- fg-文本颜色
- bg-表格背景色
- itemfg-数据文本颜色
- itembg-数据背景色
- headbg-表栏背景色
- itemactivefg-响应鼠标整行文本颜色
- itemactivebg-响应鼠标整行背景色
- itemonfg-选中时文本颜色
- itemonbg-选中时背景颜色
- scrollcolor-滚动条颜色
set_heads(heads)
设置整个表头文本。
对于
heads中的一项,如果为dict,则有如下结构:{ 'title': 'TITLE', 'width': WIDTH-INT // 宽度 }
set_head(index:int, head)
设置某个表头文本。
head可以为
str,也可以同上为dict。
append_content(content)
加入一行数据。
content中的每一个元素,如果是字符串,则是常规文本,如果是字典,应当具备基本数据:{'text':TEXT, 'type':TYPE, ...},TYPE如下:
text,普通文本check,复选框。另外接收command回调函数(默认None)、colors配色(默认TinUI标准配色)、val初始值(默认False)button,圆角按钮。另外接收command回调函数、colors配色edit,可编辑内容。另外接收command回调函数(接收修改后文本)、colors配色
set_contents(index:int, contents:list)
设置一行数据(从表头栏下一行开始记为0)。
set_content(index:int, index2:int, content:str)
设置index行index2列的数据。
get_selected(specific=False)
获取当前选中行中的所有文本列表,无则返回None。
当specific为True时,返回选中块的文本。
get_selected_item()
获取当前选中的画布元素。
get_selected_row()
获取选择行的位置。
get_selected_col()
获取选择列的位置。
get_nearby_item(pos:tuple)
获取离pos最近的画布元素列表。为了方便使用,这里的pos应当是控件坐标,TinUISheet会自动将其转换为画布坐标。
delete_row(index:int)
删除某行。
无法删除表头。
delete_col(index:int)
删除某列。
delete_all()
删除所有行。
bind(sequence:str, func, add:bool=False)
TinUISheet的事件绑定方法,同tkinter一般控件。返回funcid。
unbind(sequence:str, funcid:int=None)
事件解绑。
示例
from tkinter import Tk
from tinui import BasicTinUI, ExpandPanel, HorizonPanel
def test(_):
tus.delete_col(0)
tus.delete_row(0)
tus.set_head(0, {'title':'α', 'width':200})
tus.set_head(1, 'bbb')
for _ in range(30):
tus.append_content(['三','444','555',' ',' '])
pass
root = Tk()
root.geometry("400x400")
ui = BasicTinUI(root)
ui.pack(expand=True, fill='both')
tus = TinUISheet(ui, (15,15), **sheetlight)
tus.set_heads(['a',{'title':'b','width':200},'c',' ',' ',' '])
tus.append_content(['一',{'text':'222','type':'check'},{'text':'333', 'type':'button'},' ',' ',' '])
tus.append_content(['四',{'text':'5\n55','type':'check','val':True},'666',' ',' ',' '])
tus.append_content([{'text':'七','type':'edit','command':print},{'text':'888','type':'check'},'999',' ',' ',' '])
tus.append_content(['万',{'text':'000','type':'check'},'111',' ',' ',' '])
tus.append_content(['三',{'text':'444','type':'check'},'555',' ',' ',' '])
tus.set_contents(1, ['Ⅳ',{'text':'⑤','type':'check'},'陆',' ',' ',' '])
tus.set_content(2, 2, '玖')
ui.after(2000, lambda: print(tus.get_selected(True)))
rp = ExpandPanel(ui)
hp = HorizonPanel(ui, spacing=10)
rp.set_child(hp)
ep = ExpandPanel(ui)
hp.add_child(ep, weight=1)
ep.set_child(tus.uid)
hp.add_child(ui.add_button((10,350), text='test', command=test)[-1], 100)
def update(e):
rp.update_layout(5,5,e.width-5,e.height-5)
ui.bind('<Configure>',update)
root.mainloop()
若要使用更高级的tkinter表格功能,可以使用
tksheet库。从add_ui获取画布控件,再将Sheet控件pack(fill='both',expand=True)即可,这样可以由TinUI负责Sheet的布局。
Metadata
Release files for tinuisheet 1.7.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tinuisheet-1.7.1.tar.gz | 14.1 kB | Without provenance | Details for tinuisheet-1.7.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tinuisheet-1.7.1-py3-none-any.whl | Python 3 | none | any | Details for tinuisheet-1.7.1-py3-none-any.whl |
Total release size: 26.9 kB
Release files / tinuisheet-1.7.1.tar.gz
| Download URL | tinuisheet-1.7.1.tar.gz |
|---|---|
| Size | 14.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bef8803ed27af3c7429e2b3fc04531d64ec87afb27912989e8c6fcd71071768e
|
|
BLAKE2b-256 checksum How to use checksums |
95a30121ea8f59ff7dac9d8d4148f1921a11ba18f960a08c44b01cca76eab60a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.14
|
Release files / tinuisheet-1.7.1-py3-none-any.whl
| Download URL | tinuisheet-1.7.1-py3-none-any.whl |
|---|---|
| Size | 12.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e042336715631e5bffba1a88111300d987762a45696d8f3e11674d9724c1a439
|
|
BLAKE2b-256 checksum How to use checksums |
973f9623df9cb297783b8f18b287f98c124696a723f3610df7a4defcafcf8f50
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.14
|
Security for tinuisheet 1.7.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.