# encoding: utf-8
# 版權所有 2024 ©塗聚文有限公司
# 許可資訊查看:言語成了邀功的功臣,還需要行爲每日來值班嗎?
# 描述: 主、子表單 窗體傳值 Parent-child form operations
# Author : geovindu,Geovin Du 塗聚文.
# IDE : PyCharm 2023.1 python 3.11
# OS : windows 10
# Datetime : 2024/11/05 20:09
# User : geovindu
# Product : PyCharm
# Project : IctGame
# File : ttkbootstrap.py
# explain : 學習
import ttkbootstrap as ttk
from ttkbootstrap.constants import *
from ttkbootstrap.tableview import Tableview
'''
https://ttkbootstrap.readthedocs.io/en/latest/themes/light/
https://ttkbootstrap.readthedocs.io/en/latest/themes/dark/
https://ttkbootstrap.readthedocs.io/en/latest/zh/api/tableview/tableview/
https://ttkbootstrap.readthedocs.io/en/latest/styleguide/entry/
https://docs.pysimplegui.com/en/latest/documentation/module/extending/event_bindings/
https://python-course.eu/tkinter/events-and-binds-in-tkinter.php
cerulean
cosmo
cyborg
darkly
flatly
journal
litera
lumen
lux
materia
minty
morph
pulse
quartz
sandstone
simplex
sketchy
sketchy
solar
spacelab
superhero
united
vapor
vapor
zephyr
'''
class MainWidnow(ttk.Window):
"""
"""
def __init__(self):
"""
"""
super().__init__(themename="cosmo",title="塗聚文學習進行中")
#self.Window(themename="cosmo") #superhero
self.maxsize=300
#self.geometry('{}x{}'.format(1350, 900))
self.first_var = ttk.Variable()
self.title="main"
self.themename='superhero'
self.last_var = ttk.Variable()
self.occupation_var = ttk.Variable()
self.colors = self.style.colors
self.coldata = [
{"text": "LicenseNumber", "stretch": False},
"CompanyName",
{"text": "UserCount", "stretch": False},
]
self.rowdata = [
('A100', '深圳市分公司', 120),
('A101', '廣州市分公司.', 145),
('A102', '東莞市分公司.', 136),
('A103', '惠州市分公司', 112),
('A104', '徽州市分公司.', 245),
('A105', '佛山市分公司.', 236),
('A106', '陽江市分公司', 212),
('A107', '江門市分公司.', 345),
('A108', '中山市分公司.', 336),
('A109', '河源市分公司', 312),
('A110', '贛州市分公司.', 445),
('A111', '湖州市分公司.', 436),
('A112', '抚州市分公司', 412),
('A113', '南昌市分公司.', 545),
('A114', '饒州市分公司.', 536),
('A115', '吉州市分公司', 512),
('A116', '濟州市分公司', 645),
('A117', '冀州市分公司.', 636),
('A118', '薊州市分公司', 612),
('A119', '雷州市分公司.', 745),
('A120', '台州市分公司.', 736),
('A121', '泰州市分公司', 712),
('A122', '南京市分公司.', 845),
('A123', '常州市分公司.', 836),
('A124', '青州市分公司', 812),
('A125', '德州市分公司.', 945),
('A126', '幽州市分公司.', 36),
('A127', '杭州市分公司', 912),
('A128', '溫州市分公司.', 945),
('A129', '泉州市分公司', 1036),
('A130', '文州市分公司', 1012),
('A131', '海州市分公司.', 1045),
('A132', '儋州市分公司.', 1136),
('A133', '江州市分公司', 1112),
('A134', '上海市分公司.', 1145),
('A135', '北京市分公司.', 1136)]
self.dt = Tableview(
master=self,
coldata=self.coldata,
rowdata=self.rowdata,
paginated=True,
pagesize=15,
searchable=True,
bootstyle=PRIMARY,
stripecolor=(self.colors.light, None),
)
self.dt.pack(fill=BOTH, expand=YES, padx=10, pady=10)
#dt.hide_selected_column(cid=0) #隱藏第一列
self.dt.view.bind("<Double-1>", self.rowselected)
#dt.view.bind("<<TreeviewSelect>>", rowselected)
b1 = ttk.Button(self, text="Open", bootstyle="success") #,command=self.openwindows
b1.pack(side=LEFT, padx=5, pady=10)
#b1.bind("<Double-1>",openwindows)
b1.bind("<Button-1>",self.openwindows)
b2 = ttk.Button(self, text="New", bootstyle="info-outline")
b2.pack(side=LEFT, padx=5, pady=10)
def rowselected(self,event) -> None:
try:
iid =self.dt.view.selection()[0]
#print(iid)
values = self.dt.view.item(iid, 'values')
self.first_var.set(values[0])
self.last_var.set(values[1])
self.occupation_var.set(values[2])
print(values[0],values[1],values[2])
data=[values[0],values[1],values[2]]
subwindow = ChildNewWindow(data)
except IndexError as err:
pass
def openwindows(self,event):
"""
"""
try:
print('open windows')
iid =self.dt.view.selection()[0]
values = self.dt.view.item(iid, 'values')
data=[values[0],values[1],values[2]]
subwindow = ChildNewWindow(data)
self.update()
except IndexError as err:
pass
class ChildNewWindow(ttk.Window):
"""
彈出子窗口 ttk.Toplevel
"""
def __init__(self,data):
"""
:param master:
"""
super().__init__(title='Child Window')
self.geometry('{}x{}'.format(850, 900))
self.title='Child Window'
self.label = ttk.Label(self, text=data[0])
self.label.pack()
self.labe2 = ttk.Label(self, text=data[1])
self.labe2.pack()
self.labe3 = ttk.Label(self, text=data[2])
self.labe3.pack()
if __name__=="__main__":
"""
main output
"""
mainwindow=MainWidnow()
mainwindow.mainloop()
輸出: