欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python實(shí)現(xiàn)Excel表內(nèi)關(guān)鍵字查修改刪

 更新時間:2025年04月11日 08:42:37   作者:創(chuàng)客白澤  
在日常辦公和數(shù)據(jù)處理中,Excel作為最常用的表格工具,承載著海量業(yè)務(wù)數(shù)據(jù),但對于有些場景也會力不從心,本文將使用Python開發(fā)一個Excel表內(nèi)關(guān)鍵字查修改刪工具,需要的可以參考下

1. 概述:為什么需要這樣一款工具

在日常辦公和數(shù)據(jù)處理中,Excel作為最常用的表格工具,承載著海量業(yè)務(wù)數(shù)據(jù)。但面對以下場景時,原生Excel功能往往顯得力不從心:

  • 多條件模糊搜索:需要同時匹配多個字段中的關(guān)鍵字(支持同義詞、錯別字等)
  • 批量精準(zhǔn)修改:對篩選結(jié)果進(jìn)行統(tǒng)一編輯而避免影響其他數(shù)據(jù)
  • 安全刪除:可視化確認(rèn)后刪除指定行數(shù)據(jù)
  • 大數(shù)據(jù)處理:當(dāng)表格行數(shù)超過10萬時,原生Excel卡頓嚴(yán)重

本文介紹的基于Python Tkinter開發(fā)的Excel表內(nèi)關(guān)鍵字查修改刪工具,正是為解決這些痛點(diǎn)而生。下面將從技術(shù)實(shí)現(xiàn)到應(yīng)用場景,全面解析這款效率工具的開發(fā)思路和使用技巧。

2. 核心功能與技術(shù)實(shí)現(xiàn)

1. 整體架構(gòu)設(shè)計(jì)

class ExcelProcessor:
    def __init__(self, root):
        # 初始化GUI窗口
        self.setup_ui()  # 界面布局
        self.df = None    # Pandas DataFrame存儲數(shù)據(jù)
        self.file_path = None  # 文件路徑

工具采用經(jīng)典的MVC模式:

  • Model層:Pandas DataFrame處理數(shù)據(jù)
  • View層:Tkinter實(shí)現(xiàn)GUI界面
  • Controller層:事件綁定和業(yè)務(wù)邏輯

2. 關(guān)鍵技術(shù)點(diǎn)解析

智能搜索功能

# 多條件搜索實(shí)現(xiàn)
keywords = [kw.strip() for kw in entry.get().replace(',', ',').split(',')]
pattern = '|'.join(keywords)
filtered_df = filtered_df[filtered_df[column].astype(str).str.contains(
    pattern, case=False, na=False, regex=True)]

特點(diǎn):

  • 支持中英文逗號分隔的多關(guān)鍵字
  • 不區(qū)分大小寫
  • 自動忽略空值
  • 使用正則表達(dá)式實(shí)現(xiàn)模糊匹配

高性能表格渲染

# 動態(tài)計(jì)算列寬
max_widths = {}
for column in self.df.columns:
    header_width = len(str(column)) * 10
    max_data_width = self.df[column].astype(str).str.len().max() * 10
    max_widths[column] = min(max(header_width, max_data_width, 100), 300)

優(yōu)化點(diǎn):

  • 根據(jù)內(nèi)容動態(tài)調(diào)整列寬
  • 雙滾動條設(shè)計(jì)(水平+垂直)
  • 支持點(diǎn)擊表頭排序

安全編輯機(jī)制

def edit_row(self):
    # 創(chuàng)建獨(dú)立編輯窗口
    edit_window = tk.Toplevel(self.root)
    # 顯示所有字段可編輯
    for i, (column, value) in enumerate(zip(self.df.columns, values)):
        entry = ttk.Entry(frame)
        entry.insert(0, str(value))

特點(diǎn):

  • 模態(tài)窗口防止誤操作
  • 完整顯示所有字段
  • 類型自動轉(zhuǎn)換保障數(shù)據(jù)一致性

3. 工具使用全指南

1. 基礎(chǔ)操作流程

文件導(dǎo)入:點(diǎn)擊"選擇Excel文件"按鈕

條件設(shè)置:

  • 默認(rèn)顯示2個搜索條件
  • 可點(diǎn)擊"添加條件"增加至多條件組合
  • 支持刪除多余條件

執(zhí)行搜索:點(diǎn)擊"搜索"按鈕查看結(jié)果

數(shù)據(jù)操作:

  • 編輯:雙擊或點(diǎn)擊"編輯選中行"
  • 刪除:選中后點(diǎn)擊"刪除選中行"
  • 保存結(jié)果:點(diǎn)擊"保存更改"寫入原文件

2. 高級功能技巧

批量替換模式

  • 搜索目標(biāo)數(shù)據(jù)
  • Ctrl+多選需要修改的行
  • 在編輯窗口統(tǒng)一修改特定字段
  • 批量保存

數(shù)據(jù)清洗方案

# 刪除空值的快捷操作
def search_data(self):
    # 在搜索框輸入特定標(biāo)記如"$NULL$"
    if entry.get() == "$NULL$":
        filtered_df = filtered_df[filtered_df[column].isna()]

快捷鍵備忘

操作快捷鍵
快速搜索Ctrl+Enter
多選Ctrl+鼠標(biāo)點(diǎn)擊
全選Ctrl+A

4. 性能優(yōu)化實(shí)踐

1. 大數(shù)據(jù)處理方案

當(dāng)處理超過50萬行數(shù)據(jù)時:

# 分塊讀取優(yōu)化
chunk_size = 100000
chunks = pd.read_excel(file_path, chunksize=chunk_size)
self.df = pd.concat(chunks)

2. 內(nèi)存管理技巧

使用del釋放不再需要的變量

定期調(diào)用gc.collect()

避免在循環(huán)中創(chuàng)建大型臨時對象

3. 異步加載實(shí)現(xiàn)

from threading import Thread

def open_file_async(self):
    Thread(target=self._open_file_task, daemon=True).start()

def _open_file_task(self):
    # 實(shí)際文件操作代碼
    self.root.after(0, self.update_ui_after_loading)

5.運(yùn)行效果

6.相關(guān)源碼

import tkinter as tk
from tkinter import ttk, filedialog, messagebox
import pandas as pd
import openpyxl
 
class ExcelProcessor:
    def __init__(self, root):
        self.root = root
        self.root.title('Excel表內(nèi)關(guān)鍵字查修改刪')
        self.df = None
        self.file_path = None
        # 設(shè)置默認(rèn)窗口大小
        window_width = 1200
        window_height = 900
        screen_width = root.winfo_screenwidth()
        screen_height = root.winfo_screenheight()
        x = (screen_width - window_width) // 2
        y = (screen_height - window_height) // 2
        root.geometry(f"{window_width}x{window_height}+{x}+{y}")
        # 設(shè)置窗口最小尺寸
        root.minsize(1000, 800)
        self.setup_ui()
 
    def setup_ui(self):
        # 設(shè)置主窗口樣式
        style = ttk.Style()
        style.configure('TLabelframe', padding=8)
        style.configure('TButton', padding=5)
        style.configure('TFrame', padding=3)
        style.configure('TLabel', padding=2)
        style.configure('TEntry', padding=2)
         
        # 設(shè)置窗口圖標(biāo)
        try:
            # 獲取圖標(biāo)文件路徑
            import sys
            if getattr(sys, 'frozen', False):
                # 打包后的路徑
                base_path = sys._MEIPASS
            else:
                # 開發(fā)環(huán)境路徑
                base_path = os.path.dirname(os.path.abspath(__file__))
             
            icon_path = os.path.join(base_path, 'logo.ico')
            self.root.iconbitmap(icon_path)
        except:
            pass
 
        # 文件選擇區(qū)域
        file_frame = ttk.LabelFrame(self.root, text='文件操作')
        file_frame.pack(fill='x', padx=8, pady=(8,4))
 
        btn_container = ttk.Frame(file_frame)
        btn_container.pack(pady=8)
 
        self.file_btn = ttk.Button(btn_container, text='選擇Excel文件', command=self.open_file, width=15)
        self.file_btn.pack(side='left', padx=8)
 
        self.save_btn = ttk.Button(btn_container, text='保存更改', command=self.save_file, state='disabled', width=15)
        self.save_btn.pack(side='left', padx=8)
 
        # 搜索條件區(qū)域
        search_frame = ttk.LabelFrame(self.root, text='搜索條件')
        search_frame.pack(fill='x', padx=8, pady=6)
 
        self.search_entries = []
        self.search_combos = []
        self.search_frames = []
 
        search_controls = ttk.Frame(search_frame)
        search_controls.pack(fill='x', pady=8)
 
        # 默認(rèn)添加兩個搜索條件
        for _ in range(2):
            self.add_search_condition()
 
        control_frame = ttk.Frame(search_frame)
        control_frame.pack(fill='x', pady=8)
 
        self.add_condition_btn = ttk.Button(control_frame, text='添加條件', command=self.add_search_condition, width=12)
        self.add_condition_btn.pack(side='left', padx=8)
 
        self.search_btn = ttk.Button(control_frame, text='搜索', command=self.search_data, state='disabled', width=12)
        self.search_btn.pack(side='left', padx=8)
 
        # 數(shù)據(jù)顯示區(qū)域
        data_frame = ttk.LabelFrame(self.root, text='數(shù)據(jù)顯示')
        data_frame.pack(fill='both', expand=True, padx=8, pady=6)
 
        # 創(chuàng)建表格容器
        table_container = ttk.Frame(data_frame)
        table_container.pack(fill='both', expand=True, padx=8, pady=8)
 
        # 創(chuàng)建表格
        self.tree = ttk.Treeview(table_container)
        self.tree.pack(fill='both', expand=True, side='left')
 
        # 添加垂直滾動條
        y_scrollbar = ttk.Scrollbar(table_container, orient='vertical', command=self.tree.yview)
        y_scrollbar.pack(fill='y', side='right')
 
        # 添加水平滾動條
        x_scrollbar = ttk.Scrollbar(table_container, orient='horizontal', command=self.tree.xview)
        x_scrollbar.pack(fill='x', side='bottom')
 
        self.tree.configure(yscrollcommand=y_scrollbar.set, xscrollcommand=x_scrollbar.set)
 
        # 操作按鈕區(qū)域
        # 操作按鈕區(qū)域
        btn_frame = ttk.LabelFrame(self.root, text='操作')
        btn_frame.pack(fill='x', padx=8, pady=(6,8))
         
        btn_container = ttk.Frame(btn_frame)
        btn_container.pack(fill='x', pady=8)
         
        self.edit_btn = ttk.Button(btn_container, text='編輯選中行', command=self.edit_row, state='disabled', width=12)
        self.edit_btn.pack(side='left', padx=8)
         
        self.delete_btn = ttk.Button(btn_container, text='刪除選中行', command=self.delete_row, state='disabled', width=12)
        self.delete_btn.pack(side='left', padx=8)
         
        
 
    def open_file(self):
        file_path = filedialog.askopenfilename(filetypes=[
            ('Excel文件', '*.xlsx;*.xls')
        ])
        if file_path:
            try:
                # 禁用按鈕,顯示加載提示
                self.file_btn['state'] = 'disabled'
                self.root.config(cursor='wait')
                self.root.update()
 
                self.file_path = file_path
                self.df = pd.read_excel(file_path)
                self.update_table()
                self.update_search_fields()
                self.enable_buttons()
 
                # 恢復(fù)按鈕狀態(tài)和光標(biāo)
                self.file_btn['state'] = 'normal'
                self.root.config(cursor='')
                messagebox.showinfo('成功', '文件加載成功!')
            except Exception as e:
                self.file_btn['state'] = 'normal'
                self.root.config(cursor='')
                messagebox.showerror('錯誤', f'文件加載失敗:{str(e)}')
 
    def update_table(self):
        # 清空現(xiàn)有數(shù)據(jù)
        for item in self.tree.get_children():
            self.tree.delete(item)
 
        # 設(shè)置列
        self.tree['columns'] = list(self.df.columns)
        self.tree['show'] = 'headings'
 
        # 計(jì)算每列的最大寬度
        max_widths = {}
        for column in self.df.columns:
            # 計(jì)算列標(biāo)題的寬度
            header_width = len(str(column)) * 10
            # 計(jì)算數(shù)據(jù)的最大寬度
            max_data_width = self.df[column].astype(str).str.len().max() * 10
            max_widths[column] = min(max(header_width, max_data_width, 100), 300)
 
        for column in self.df.columns:
            self.tree.heading(column, text=column,
                command=lambda col=column: self.sort_treeview(col))
            self.tree.column(column, width=max_widths[column], minwidth=50)
 
        # 添加數(shù)據(jù)
        for idx, row in self.df.iterrows():
            self.tree.insert('', 'end', values=list(row))
 
    def sort_treeview(self, col):
        """對表格按指定列排序"""
        if not hasattr(self, 'sort_reverse'):
            self.sort_reverse = {}
        self.sort_reverse[col] = not self.sort_reverse.get(col, False)
 
        # 獲取所有數(shù)據(jù)
        data = [(self.tree.set(child, col), child) for child in self.tree.get_children('')]
         
        # 排序
        data.sort(reverse=self.sort_reverse[col])
         
        # 重新插入數(shù)據(jù)
        for idx, item in enumerate(data):
            self.tree.move(item[1], '', idx)
 
    def update_search_fields(self):
        columns = list(self.df.columns)
        for combo in self.search_combos:
            combo['values'] = columns
            if columns:
                combo.set(columns[0])
 
    def enable_buttons(self):
        self.save_btn['state'] = 'normal'
        self.search_btn['state'] = 'normal'
        self.edit_btn['state'] = 'normal'
        self.delete_btn['state'] = 'normal'
 
    def search_data(self):
        if self.df is None:
            return
 
        try:
            # 禁用搜索按鈕并顯示等待光標(biāo)
            self.search_btn['state'] = 'disabled'
            self.root.config(cursor='wait')
            self.root.update()
 
            filtered_df = self.df.copy()
            for combo, entry in zip(self.search_combos, self.search_entries):
                if combo.get() and entry.get():
                    column = combo.get()
                    # 將輸入值按全角和半角逗號分割成多個關(guān)鍵字
                    keywords = [kw.strip() for kw in entry.get().replace(',', ',').split(',')]
                    # 使用正則表達(dá)式構(gòu)建'或'的檢索條件
                    pattern = '|'.join(keywords)
                    filtered_df = filtered_df[filtered_df[column].astype(str).str.contains(pattern, case=False, na=False, regex=True)]
 
            # 更新顯示
            self.update_table_with_df(filtered_df)
 
            if len(filtered_df) == 0:
                messagebox.showinfo('提示', '未找到匹配的數(shù)據(jù)')
        except Exception as e:
            messagebox.showerror('錯誤', f'搜索失?。簕str(e)}')
        finally:
            # 恢復(fù)搜索按鈕狀態(tài)和光標(biāo)
            self.search_btn['state'] = 'normal'
            self.root.config(cursor='')
            self.root.update()
 
    def update_table_with_df(self, df):
        for item in self.tree.get_children():
            self.tree.delete(item)
        for idx, row in df.iterrows():
            self.tree.insert('', 'end', values=list(row))
 
    def edit_row(self):
        selected_items = self.tree.selection()
        if not selected_items:
            messagebox.showwarning('警告', '請先選擇要編輯的行!')
            return
 
        # 獲取選中行的數(shù)據(jù)
        item = selected_items[0]
        values = self.tree.item(item)['values']
         
        # 創(chuàng)建編輯窗口
        edit_window = tk.Toplevel(self.root)
        edit_window.title('編輯數(shù)據(jù)')
        edit_window.transient(self.root)  # 設(shè)置為主窗口的子窗口
        edit_window.grab_set()  # 模態(tài)窗口
         
        # 創(chuàng)建滾動區(qū)域
        canvas = tk.Canvas(edit_window)
        scrollbar = ttk.Scrollbar(edit_window, orient='vertical', command=canvas.yview)
        scrollable_frame = ttk.Frame(canvas)
 
        scrollable_frame.bind(
            '<Configure>',
            lambda e: canvas.configure(scrollregion=canvas.bbox('all'))
        )
 
        canvas.create_window((0, 0), window=scrollable_frame, anchor='nw')
        canvas.configure(yscrollcommand=scrollbar.set)
         
        entries = []
        for i, (column, value) in enumerate(zip(self.df.columns, values)):
            frame = ttk.Frame(scrollable_frame)
            frame.pack(fill='x', padx=10, pady=3)
            ttk.Label(frame, text=f'{column}:', width=15).pack(side='left')
            entry = ttk.Entry(frame)
            entry.insert(0, str(value))
            entry.pack(side='left', fill='x', expand=True, padx=5)
            entries.append(entry)
 
        # 按鈕區(qū)域
        btn_frame = ttk.Frame(edit_window)
        btn_frame.pack(fill='x', padx=10, pady=10)
 
        def save_changes():
            try:
                edit_window.config(cursor='wait')
                edit_window.update()
                 
                new_values = [entry.get() for entry in entries]
                # 更新DataFrame
                idx = self.tree.index(item)
                for col, value in zip(self.df.columns, new_values):
                    self.df.iloc[idx, self.df.columns.get_loc(col)] = value
                # 更新樹形視圖
                self.tree.item(item, values=new_values)
                edit_window.destroy()
                messagebox.showinfo('成功', '數(shù)據(jù)更新成功!')
            except Exception as e:
                edit_window.config(cursor='')
                messagebox.showerror('錯誤', f'保存失?。簕str(e)}')
 
        def cancel_edit():
            edit_window.destroy()
 
        ttk.Button(btn_frame, text='保存', command=save_changes).pack(side='left', padx=5)
        ttk.Button(btn_frame, text='取消', command=cancel_edit).pack(side='left')
 
        # 設(shè)置滾動區(qū)域布局
        canvas.pack(side='left', fill='both', expand=True, padx=5, pady=5)
        scrollbar.pack(side='right', fill='y')
 
        # 設(shè)置窗口大小和位置
        edit_window.update()
        window_width = min(edit_window.winfo_reqwidth() + 30, 800)
        window_height = min(edit_window.winfo_reqheight() + 30, 600)
        screen_width = edit_window.winfo_screenwidth()
        screen_height = edit_window.winfo_screenheight()
        x = (screen_width - window_width) // 2
        y = (screen_height - window_height) // 2
        edit_window.geometry(f'{window_width}x{window_height}+{x}+{y}')
 
    def delete_row(self):
        selected_items = self.tree.selection()
        if not selected_items:
            messagebox.showwarning('警告', '請先選擇要刪除的行!')
            return
 
        if messagebox.askyesno('確認(rèn)', '確定要刪除選中的行嗎?'):
            for item in selected_items:
                idx = self.tree.index(item)
                self.df.drop(self.df.index[idx], inplace=True)
                self.tree.delete(item)
            self.df.reset_index(drop=True, inplace=True)
            messagebox.showinfo('成功', '數(shù)據(jù)刪除成功!')
 
    def save_file(self):
        if self.file_path and self.df is not None:
            try:
                self.df.to_excel(self.file_path, index=False)
                messagebox.showinfo('成功', '文件保存成功!')
            except Exception as e:
                messagebox.showerror('錯誤', f'文件保存失敗:{str(e)}')
 
    def add_search_condition(self):
        frame = ttk.Frame(self.root.children['!labelframe2'].children['!frame'])
        frame.pack(fill='x', pady=3)
         
        condition_num = len(self.search_frames) + 1
        ttk.Label(frame, text=f'條件{condition_num}:', width=8).pack(side='left')
         
        combo = ttk.Combobox(frame, state='readonly', width=20)
        combo.pack(side='left', padx=(0,5))
         
        entry = ttk.Entry(frame)
        entry.pack(side='left', padx=5, fill='x', expand=True)
        # 添加提示標(biāo)簽
        ttk.Label(frame, text='(可用逗號分隔多個關(guān)鍵字)', foreground='gray').pack(side='left', padx=5)
         
        # 添加刪除按鈕
        def remove_condition():
            frame.destroy()
            self.search_frames.remove(frame)
            self.search_combos.remove(combo)
            self.search_entries.remove(entry)
            # 更新剩余條件的編號
            for i, f in enumerate(self.search_frames, 1):
                f.children['!label']['text'] = f'條件{i}:'
         
        if len(self.search_frames) > 1:  # 只有當(dāng)有多個條件時才顯示刪除按鈕
            delete_btn = ttk.Button(frame, text='×', width=3, command=remove_condition)
            delete_btn.pack(side='left', padx=(5,0))
         
        self.search_frames.append(frame)
        self.search_combos.append(combo)
        self.search_entries.append(entry)
         
        if self.df is not None:
            combo['values'] = list(self.df.columns)
            if combo['values']:
                combo.set(combo['values'][0])
 
    def show_help(self):
        help_window = tk.Toplevel(self.root)
        help_window.title('使用說明')
        help_window.transient(self.root)
        help_window.grab_set()
 
        # 創(chuàng)建滾動區(qū)域
        canvas = tk.Canvas(help_window)
        scrollbar = ttk.Scrollbar(help_window, orient='vertical', command=canvas.yview)
        scrollable_frame = ttk.Frame(canvas)
 
        scrollable_frame.bind(
            '<Configure>',
            lambda e: canvas.configure(scrollregion=canvas.bbox('all'))
        )
 
        canvas.create_window((0, 0), window=scrollable_frame, anchor='nw')
        canvas.configure(yscrollcommand=scrollbar.set)
 
        # 讀取README.md文件內(nèi)容
        try:
            # 獲取資源文件路徑
            import sys
            if getattr(sys, 'frozen', False):
                # 打包后的路徑
                base_path = sys._MEIPASS
            else:
                # 開發(fā)環(huán)境路徑
                base_path = os.path.dirname(os.path.abspath(__file__))
             
            readme_path = os.path.join(base_path, 'README.md')
            with open(readme_path, 'r', encoding='utf-8') as f:
                help_text = f.read()
            # 僅顯示使用說明部分
            start = help_text.find('## 使用說明')
            if start != -1:
                help_text = help_text[start:]
        except Exception as e:
            help_text = f'無法加載幫助文檔:{str(e)}'
 
        # 顯示幫助文本
        text_widget = tk.Text(scrollable_frame, wrap='word', width=60, height=20)
        text_widget.insert('1.0', help_text)
        text_widget.configure(state='disabled')
        text_widget.pack(padx=10, pady=10)
 
        # 設(shè)置滾動區(qū)域布局
        canvas.pack(side='left', fill='both', expand=True)
        scrollbar.pack(side='right', fill='y')
 
        # 設(shè)置窗口大小和位置
        help_window.update()
        window_width = min(help_window.winfo_reqwidth() + 30, 800)
        window_height = min(help_window.winfo_reqheight() + 30, 600)
        screen_width = help_window.winfo_screenwidth()
        screen_height = help_window.winfo_screenheight()
        x = (screen_width - window_width) // 2
        y = (screen_height - window_height) // 2
        help_window.geometry(f'{window_width}x{window_height}+{x}+{y}')
 
    def show_reward(self):
        reward_window = tk.Toplevel(self.root)
        reward_window.title('賞贊支持')
        reward_window.transient(self.root)
        reward_window.grab_set()
 
        # 創(chuàng)建容器框架
        container = ttk.Frame(reward_window)
        container.pack(padx=20, pady=20)
 
        # 顯示感謝文字
        thank_label = ttk.Label(container, text='您的慷慨是對作者最大的支持', font=('微軟雅黑', 12))
        thank_label.pack(pady=(0, 10))
 
        # 顯示賞贊二維碼
        try:
            # 檢查PIL模塊是否可用
            try:
                from PIL import Image, ImageTk
            except ImportError:
                raise ImportError('缺少必要的圖片處理模塊。請運(yùn)行 pip install Pillow 安裝所需模塊。')
 
            import os
            # 獲取資源文件路徑
            import sys
            if getattr(sys, 'frozen', False):
                # 打包后的路徑
                base_path = sys._MEIPASS
            else:
                # 開發(fā)環(huán)境路徑
                base_path = os.path.dirname(os.path.abspath(__file__))
             
            image_path = os.path.join(base_path, 'reward.jpg')
             
            # 添加加載提示
            loading_label = ttk.Label(container, text='正在加載賞贊二維碼...')
            loading_label.pack(pady=5)
            reward_window.update()
             
            if not os.path.exists(image_path):
                loading_label.destroy()
                raise FileNotFoundError('賞贊二維碼圖片文件(reward.jpg)不存在,請確保該文件在程序目錄中。')
             
            try:
                # 加載并處理圖片
                image = Image.open(image_path)
                # 調(diào)整圖片大小,保持縱橫比
                width, height = image.size
                max_size = 300
                ratio = min(max_size/width, max_size/height)
                new_size = (int(width*ratio), int(height*ratio))
                image = image.resize(new_size, Image.Resampling.LANCZOS)
                 
                # 創(chuàng)建圖片標(biāo)簽并顯示
                photo = ImageTk.PhotoImage(image)
                image_label = ttk.Label(container, image=photo)
                image_label.image = photo  # 保持引用
                 
                # 移除加載提示并顯示圖片
                loading_label.destroy()
                image_label.pack(pady=10)
                 
                # 添加成功提示
                ttk.Label(container, text='賞贊二維碼加載成功', foreground='green').pack(pady=5)
 
                # 設(shè)置固定窗口大小
                reward_window.update()
                window_width = max(400, image_label.winfo_reqwidth() + 40)
                window_height = image_label.winfo_reqheight() + thank_label.winfo_reqheight() + 80
                reward_window.geometry(f'{window_width}x{window_height}')
            except Exception as img_error:
                loading_label.destroy()
                error_msg = f'圖片加載失敗:{str(img_error)}'
                ttk.Label(container, text=error_msg, foreground='red', wraplength=300).pack(pady=10)
                window_width = 400
                window_height = 200
                reward_window.geometry(f'{window_width}x{window_height}')
        except ImportError as e:
            error_msg = str(e)
            error_label = ttk.Label(container, text=error_msg, foreground='red', wraplength=300)
            error_label.pack(pady=10)
            window_width = 400
            window_height = 200
            reward_window.geometry(f'{window_width}x{window_height}')
        except Exception as e:
            error_msg = f'無法加載賞贊二維碼:{str(e)}'
            error_label = ttk.Label(container, text=error_msg, foreground='red', wraplength=300)
            error_label.pack(pady=10)
            window_width = 400
            window_height = 200
            reward_window.geometry(f'{window_width}x{window_height}')
 
        # 設(shè)置窗口位置
        screen_width = reward_window.winfo_screenwidth()
        screen_height = reward_window.winfo_screenheight()
        x = (screen_width - window_width) // 2
        y = (screen_height - window_height) // 2
        reward_window.geometry(f'+{x}+{y}')
 
def main():
    root = tk.Tk()
    app = ExcelProcessor(root)
    root.geometry('800x600')
    root.mainloop()
 
if __name__ == '__main__':
    main()

7.總結(jié)與擴(kuò)展思考

工具優(yōu)勢總結(jié)

  • 操作效率提升:相比原生Excel,批量操作速度提升5-10倍
  • 學(xué)習(xí)成本低:符合Windows操作習(xí)慣的GUI界面
  • 擴(kuò)展性強(qiáng):基于Python生態(tài),可輕松集成更多功能

未來擴(kuò)展方向

  • 插件系統(tǒng)開發(fā):支持用戶自定義處理邏輯
  • 云端協(xié)同:集成WebDAV實(shí)現(xiàn)多人編輯
  • AI輔助:結(jié)合NLP實(shí)現(xiàn)智能字段識別

開發(fā)經(jīng)驗(yàn)分享

在開發(fā)過程中,最值得注意的三個關(guān)鍵點(diǎn):

  • 線程安全:GUI更新必須在主線程執(zhí)行
  • 異常處理:對文件操作必須全面try-catch
  • 用戶體驗(yàn):添加適當(dāng)?shù)募虞d動畫和狀態(tài)提示

到此這篇關(guān)于Python實(shí)現(xiàn)Excel表內(nèi)關(guān)鍵字查修改刪的文章就介紹到這了,更多相關(guān)Python Excel關(guān)鍵字操作內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 5個很好的Python面試題問題答案及分析

    5個很好的Python面試題問題答案及分析

    這篇文章主要介紹了5個很好的Python面試題問題答案及分析,具有一定借鑒價值,需要的朋友可以參考下
    2018-01-01
  • 在NumPy中創(chuàng)建空數(shù)組/矩陣的方法

    在NumPy中創(chuàng)建空數(shù)組/矩陣的方法

    今天小編就為大家分享一篇在NumPy中創(chuàng)建空數(shù)組/矩陣的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-06-06
  • Python使用cx_Oracle調(diào)用Oracle存儲過程的方法示例

    Python使用cx_Oracle調(diào)用Oracle存儲過程的方法示例

    這篇文章主要介紹了Python使用cx_Oracle調(diào)用Oracle存儲過程的方法,結(jié)合具體實(shí)例分析了Python中通過cx_Oracle調(diào)用PL/SQL的具體步驟與相關(guān)操作技巧,需要的朋友可以參考下
    2017-10-10
  • Python的爬蟲包Beautiful Soup中用正則表達(dá)式來搜索

    Python的爬蟲包Beautiful Soup中用正則表達(dá)式來搜索

    這篇文章主要介紹了Python的爬蟲包Beautiful Soup中用正則表達(dá)式來搜索的技巧,包括使用正則表達(dá)式去搜索多種可能的關(guān)鍵字以及查找屬性值未知的標(biāo)簽等,需要的朋友可以參考下
    2016-01-01
  • Moviepy模塊實(shí)現(xiàn)視頻添加圖片水印

    Moviepy模塊實(shí)現(xiàn)視頻添加圖片水印

    本文主要介紹了Moviepy模塊實(shí)現(xiàn)視頻添加圖片水印,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-04-04
  • Python中?*?號的用法總結(jié)

    Python中?*?號的用法總結(jié)

    Python中的?*號是一個特殊的符號,在其他編程語言中,它最廣為人知的用途就是作為乘法運(yùn)算的符號,本文總結(jié)了Python中*號的所有用途,希望對大家有所幫助
    2023-11-11
  • 在Django中管理Users和Permissions以及Groups的方法

    在Django中管理Users和Permissions以及Groups的方法

    這篇文章主要介紹了在Django中管理Users和Permissions以及Groups的方法,Django是最具人氣的Python web開發(fā)框架,需要的朋友可以參考下
    2015-07-07
  • 如何在Python項(xiàng)目中做多環(huán)境配置(環(huán)境變量使用.env文件)

    如何在Python項(xiàng)目中做多環(huán)境配置(環(huán)境變量使用.env文件)

    實(shí)際工程開發(fā)中常常會對開發(fā)、測試和生產(chǎn)等不同環(huán)境配置不同的數(shù)據(jù)庫環(huán)境,傳統(tǒng)方式可以通過添加不同環(huán)境的配置文件達(dá)到部署時的動態(tài)切換的效果,這篇文章主要給大家介紹了關(guān)于如何在Python項(xiàng)目中做多環(huán)境配置的相關(guān)資料,環(huán)境變量使用.env文件,需要的朋友可以參考下
    2024-06-06
  • python 實(shí)現(xiàn)得到當(dāng)前時間偏移day天后的日期方法

    python 實(shí)現(xiàn)得到當(dāng)前時間偏移day天后的日期方法

    今天小編就為大家分享一篇python 實(shí)現(xiàn)得到當(dāng)前時間偏移day天后的日期方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-12-12
  • matlab xlabel位置的設(shè)置方式

    matlab xlabel位置的設(shè)置方式

    這篇文章主要介紹了matlab xlabel位置的設(shè)置方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-05-05

最新評論