import tkinter as tk
import ttkbootstrap as ttk
from random import choice
import openpyxl
from tkinter import messagebox # 弹出提示框
from tkinter.scrolledtext import ScrolledText
def datastatistics(): # excel文件数据统计分析
wb = openpyxl.load_workbook(r'C:\Users\Administrator\Desktop\2023年工作任务清单.xlsx')
sheets = wb.sheetnames
未完成任务 = []
已完成任务 = []
未完成任务计数 = 0
未完成任务分类计数 = []
已完成任务计数 = 0
已完成任务分类计数 = []
global 未完成人员计数
global 每个人完成任务计数
global 每个人未完成任务计数
未完成人员计数 = []
for i in range(len(sheets)):
sheet = wb.get_sheet_by_name(sheets[i])
# print('\n\n第' + str(i + 1) + '个sheet: ' + sheet.title + '->>>')
for r in range(1, sheet.max_row + 1):
if sheet.cell(row=r, column=10).value == "否":
未完成任务计数 = 未完成任务计数 + 1
未完成人员计数.append(sheet.title)
未完成人员计数.append((sheet.cell(row=r, column=3).value))
未完成任务分类计数.append(sheet.title)
未完成任务.append(sheet.cell(row=r, column=3).value)
if sheet.cell(row=r, column=10).value == "是":
已完成任务计数 = 已完成任务计数 + 1
已完成任务分类计数.append(sheet.title)
已完成任务.append(sheet.cell(row=r, column=3).value)
总任务数 = 未完成任务计数 + 已完成任务计数
每个人完成任务计数 = {}
每个人未完成任务计数 = {}
for i in range(len(sheets)):
sheet = wb.get_sheet_by_name(sheets[i])
每个人完成任务计数.update({sheets[i]: 已完成任务分类计数.count(sheets[i])})
每个人未完成任务计数.update({sheets[i]: 未完成任务分类计数.count(sheets[i])})
for x, y in 每个人完成任务计数.items(): # 通过使用 items() 函数遍历键和值:
print(x, y)
for x, y in 每个人未完成任务计数.items(): # 通过使用 items() 函数遍历键和值:
print(x, y)
return 总任务数, 已完成任务计数, 未完成任务计数, 未完成任务, 已完成任务
def create_labelframe_style(bootstyle, style):
global 函数返回数据
函数返回数据 = datastatistics()
frame = ttk.Frame(root, padding=5)
# title
title = ttk.Label(frame, text='Labelframe', anchor=tk.CENTER)
title.pack(padx=5, pady=2, fill=tk.BOTH)
ttk.Separator(frame, bootstyle="danger").pack(padx=5, pady=5, fill=tk.X) # 彩色分割线
# default
lbl = ttk.Labelframe(
master=frame,
text='工作任务信息统计',
bootstyle='primary',
width=150,
height=75
)
lbl.pack(padx=5, pady=5, fill=tk.BOTH)
ttk.Label(lbl, text="总任务数:").grid(row=1, column=0)
ttk.Label(lbl, text=函数返回数据[0], bootstyle='success').grid(row=1, column=1)
ttk.Label(lbl, text="未完成:").grid(row=1, column=2)
ttk.Label(lbl, text=函数返回数据[2], bootstyle='success').grid(row=1, column=3)
ttk.Label(lbl, text="已完成:").grid(row=1, column=4)
ttk.Label(lbl, text=函数返回数据[1], bootstyle='success').grid(row=1, column=5)
frame1 = ttk.Frame(root, padding=5)
lbl2 = ttk.Labelframe(master=frame,text='未完成工作任务',bootstyle='primary', width=5, height=400)
lbl2.pack_propagate(0)
lbl2.pack(padx=5, pady=5, fill=tk.BOTH)
scrolledText = ScrolledText(root, width=2, height=400)
scrolledText = ttk.ScrolledText(lbl2)
scrolledText.pack(padx=0, pady=0)
cb_var = []
global is_check_list
global aaff
is_check_list = []
v = tk.IntVar()
my_tuple=()
def truncate_string(text, max_length=14): # 这是一个超过20个字符的示例文本,我们将对其进行截断处理。
if len(text) > max_length:
return text[:max_length] + '....'
else:
return text.ljust(max_length+1," ")
for i in range(len(函数返回数据[3])):
truncated_text = truncate_string(str(i)+"."+str(函数返回数据[3][i]))
is_check_list.append(ttk.IntVar(value=0))
bb = 未完成人员计数.index(str(函数返回数据[3][i]))
cc = (未完成人员计数[bb - 1])
cb = ttk.Radiobutton(scrolledText, text=truncated_text, variable=v,
value=i,bootstyle="",command=lambda: printValue(v.get()))
scrolledText.window_create('end', window=cb)
scrolledText.insert('end', '\n')
# cb.bind('<Double-1>', aa) # 列表框绑定鼠标事件函数
# ttk.Checkbutton.deselect
# cb.bind('<Enter>', on_enter) # 绑定鼠标进入事件
return frame
def printValue(value):
print(value)
all_select = ""
for i in range(len(函数返回数据[3])):
if i == value :
print("正确")
all_select=str(函数返回数据[3][i])
aa = 函数返回数据[3][i]
bb = 未完成人员计数.index(aa)
bbb = 未完成人员计数[bb - 1]
messagebox.showinfo("提示", "你所选择的数据是:\n" + all_select + " \n[承办人:" + str(bbb) + "]")
# open_new_window()
def change_style():
theme = choice(style.theme_names())
style.theme_use(theme)
def set_window_opacity(window, opacity):
"""
设置Tkinter窗口的透明度。
参数:
window: Tk() 对象或 Toplevel 对象
opacity: 0.0 (完全透明) 到 1.0 (完全不透明) 之间的浮点数
"""
try:
# 对于Windows系统
window.attributes('-alpha', opacity)
except tk.TclError:
pass
def open_new_window():
# 创建新的窗口
new_window = tk.Toplevel(root)
new_window.title('新窗口')
new_window.geometry('400x300')
# 将新窗口居中显示
new_window.attributes('-topmost', True)
new_window.update_idletasks()
width = new_window.winfo_width()
height = new_window.winfo_height()
x = (new_window.winfo_screenwidth() // 2) - (width // 2)
y = (new_window.winfo_screenheight() // 2) - (height // 2)
new_window.geometry('{}x{}+{}+{}'.format(width, height, x, y))
new_window.attributes('-topmost', False)
# 在新窗口上添加一个标签
new_label = tk.Label(new_window, text='任务序号')
new_label.pack()
new_label1 = tk.Label(new_window, text='任务名称')
new_label1.pack()
new_label2 = tk.Label(new_window, text='任务内容')
new_label2.pack()
if __name__ == '__main__':
# create visual widget style tests
# root = ttk.Window(size=(800,600))
root = tk.Tk()
# root = ttk.Window(themename="solar") #主题
root.resizable(False, False) # 窗口不可调整大小。
root.geometry("+1200+100") # 窗口位置
# set_window_opacity(root, 0.5) # 设置50%的透明度
style = ttk.Style()
ttk.Button(text="Change Theme", command=change_style).grid(row=0, column=0)
create_labelframe_style('', style).grid(row=0, column=0)
root.mainloop()