页面 添加简要查询 实现输入后查询修改

HTML页面

<style>
    /* 固定定位的搜索框容器 */
 .fixed-top-search {
      position: fixed; /* 固定定位,悬浮不随滚动移动 */
      top: 0;          /* 锁定到页面顶部 */
      right: 20px;     /* 水平靠右 20px,可改 left: 20px 靠左,或 left: 50%; transform: translateX(-50%) 居中 */
      z-index: 9999;   /* 最高层级,避免被遮挡 */
      padding: 10px 0; /* 上下内边距,让搜索框更美观 */
      width: 320px;    /* 搜索框宽度,可调整 */
    }
</style>


<!-- 悬浮搜索框 -->
    <div class="fixed-top-search">
        <div class="input-group">
            <input type="text" class="form-control search" placeholder="请输入搜索内容" aria-label="搜索">
            <span class="input-group-addon">
                输入名称
            </span>
        </div>
    </div>

JS处理

function clearHighlight() {
  // 找到所有高亮的span,直接替换为文本内容,避免unwrap的转义问题
  $('span.bg-danger').each(function() {
    var $this = $(this);
    // console.log($this.text());
    // 替换span为其文本内容(纯文本,无HTML解析)
    // $this.replaceWith($this.text());
    $this.parent().text($this.parent().text())
  });
}

// 搜索字符串并添加 bg-danger 类
function searchAndHighlight(keyword) {

  if (!keyword.trim()) return;

  // 遍历所有文本节点(排除 script、style 标签)
  $('body :not(script, style)').contents().each(function() {
    // 只处理文本节点
    if (this.nodeType === Node.TEXT_NODE) {
      var text = $(this).text();
    //   text=text.replace(/"/g,"");
      const regex = new RegExp(`(${keyword})`, 'gi');
      
      // 匹配到关键词时,用 span 包裹
      if (regex.test(text)) {
        
        const newHtml = text.replace(regex, '<span class="bg-danger">$1</span>');
        $(this).replaceWith(newHtml);
        // $(this).addClass('bg-danger')
      }
    }
  });
}

$(".search").on("input", function(){
  var se = $(this).val().trim(); // 去除首尾空格,避免无效查询
  if (se) {
    clearHighlight();
    searchAndHighlight(se); // 有内容则高亮
  }
});
发表在 None | 留下评论

Thinkphp 前端页面获取get值

{:request()->get(‘id/d’)}
调用上面的函数可以获得 get类型的id并初始化为数字形式

发表在 None | 留下评论

python打包 pyinstaller PIL

带logo 无黑框打包

pyinstaller -F -w -i logo.ico x.py

无logo 无黑框

pyinstaller -F -w x.py

普通打包 一个 单文件exe 有黑框

pyinstaller -F x.py

普通打包 非单文件exe有黑框

pyinstaller x.py

PIL 打包坑点 需要指定 字体

#否则会失败

options = {
    'module_width': 0.24,
    'module_height':6.0,
    'font_size': 8,
    'text_distance': 3,
    'quiet_zone':4,
    'font_path': r'C:\Windows\Fonts\arial.ttf',  # Arial字体(纯数字/英文)
}
发表在 None | 留下评论

Tkinter 输入回车返回

import tkinter as tk
from tkinter import messagebox

def submit_content(event=None):
    """
    提交输入框内容的核心函数
    event 参数:绑定键盘事件时会自动传入,需保留(设为默认None兼容按钮点击)
    """
    # 获取输入框内容并去除首尾空格
    content = entry.get().strip()
    
    # 空值校验
    if not content:
        messagebox.warning("提示", "输入框不能为空!")
        # 清空输入框并让输入框重新获得焦点
        entry.delete(0, tk.END)
        entry.focus()
        return
    
    # 处理提交逻辑(这里仅做演示,你可以替换为自己的业务代码)
    messagebox.showinfo("提交成功", f"你提交的内容是:{content}")
    
    # 提交后清空输入框并保持焦点,方便继续输入
    entry.delete(0, tk.END)
    entry.focus()

# 创建主窗口
root = tk.Tk()
root.title("回车提交输入框内容")
root.geometry("400x200")

# 创建输入框
entry = tk.Entry(
    root,
    font=("Arial", 14),
    width=30
)
entry.pack(pady=30)

# 核心:绑定回车键事件(<Return> 对应回车键)
entry.bind("<Return>", submit_content)

# 可选:添加提交按钮(兼容鼠标点击场景)
submit_btn = tk.Button(
    root,
    text="提交",
    font=("Arial", 12),
    command=submit_content  # 直接调用函数,无需传参(因为event设为默认None)
)
submit_btn.pack()

# 让输入框默认获得焦点,打开窗口即可直接输入
entry.focus()

# 运行主循环
root.mainloop()
发表在 None | 留下评论

打印机 python使用 Pillow pywin32

import barcode
from barcode.writer import ImageWriter
from PIL import Image,ImageWin
import win32print
import win32ui

options = {
    'module_width': 0.24,
    'module_height':6.0,
    'font_size': 8,
    'text_distance': 3,
    'quiet_zone':4,
}


def print_img(image_path):
    mr_id=0
    has_750=False
    done=False
    printers = [printer[2] for printer in win32print.EnumPrinters(2)]
    for i, printer in enumerate(printers):
        # print(f"{i+1}: {printer}")
        if '750' in printer:
            mr_id=i
            has_750=True
            printer_name=printers[i]
    if has_750:
        print("已经提交给打印机",printer_name,"打印条码")
        image = Image.open(image_path)
        hDC = win32ui.CreateDC()
        hDC.CreatePrinterDC(printer_name)
        hDC.StartDoc(image_path)
        hDC.StartPage()
        dib = ImageWin.Dib(image)
        dib.draw(hDC.GetHandleOutput(), (0, 0, image.width, image.height))
        hDC.EndPage()
        hDC.EndDoc()
        del hDC
        done=True
    return done

def makeCode(code):
    Code128 = barcode.get_barcode_class('code128')
    code128 = Code128(code, writer=ImageWriter())
    filename = code128.save('print_swap',options=options)
    image_path=filename
    print_img(image_path)


code='HTA101CWGL0120260001'
makeCode(code)


发表在 None | 留下评论