找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
楼主: zzz19760225

批处理勇士大闯关改中医许阳批处理的可能

[复制链接]
 楼主| 发表于 2026-6-27 16:54:21 | 显示全部楼层
1234567890
 楼主| 发表于 2026-6-27 16:54:54 | 显示全部楼层
1234567890
 楼主| 发表于 2026-6-27 16:55:03 | 显示全部楼层
1234567890
 楼主| 发表于 2026-6-27 16:55:09 | 显示全部楼层

perl图文混编的命令输入界面

本帖最后由 zzz19760225 于 2026-7-15 20:41 编辑
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use utf8;
  5. use open ':std', ':encoding(utf8)';
  6. use Tk;

  7. # 配置参数
  8. my $MAX_LINES = 1000;  # 最多保留1000行
  9. my $MAX_BYTES = 20 * 1024 * 1024;  # 最多保留10MB

  10. # 创建主窗口
  11. my $mw = MainWindow->new;
  12. $mw->title("Text 图文混排 - 命令行模式");
  13. $mw->geometry("800x600");

  14. # 创建主框架
  15. my $main_frame = $mw->Frame->pack(-fill => 'both', -expand => 1);

  16. # 创建显示区域(上方)
  17. my $text = $main_frame->Scrolled('Text',
  18.     -wrap   => 'word',
  19.     -font   => '{DejaVu Sans} 12',
  20.     -background => 'white',
  21.     -foreground => 'black',
  22.     -scrollbars => 'osoe',  # 自动显示/隐藏滚动条
  23. )->pack(-fill => 'both', -expand => 1, -side => 'top');

  24. # 设置显示区域为只读
  25. $text->configure(-state => 'disabled');

  26. # 创建底部输入框架
  27. my $input_frame = $main_frame->Frame(
  28.     -background => 'lightgray',
  29. )->pack(-fill => 'x', -side => 'bottom');

  30. # 命令输入框
  31. my $input = $input_frame->Entry(
  32.     -font => ['DejaVu Sans', 12],
  33.     -background => 'white',
  34.     -foreground => 'black',
  35.     -insertbackground => 'black',
  36.     -relief => 'sunken',
  37.     -bd => 2,
  38. )->pack(-side => 'left', -fill => 'x', -expand => 1, -padx => 5, -pady => 5);

  39. # 状态标签(显示行数等信息)
  40. my $status_label = $input_frame->Label(
  41.     -text => '行数: 0',
  42.     -font => ['DejaVu Sans', 9],
  43.     -background => 'lightgray',
  44.     -foreground => 'gray30',
  45. )->pack(-side => 'right', -padx => 5);

  46. # 绑定回车键
  47. $input->bind('<Return>' => \&process_command);

  48. # 安全地插入内容(带限制)
  49. sub insert_with_limit {
  50.     my ($content) = @_;
  51.    
  52.     # 启用编辑
  53.     $text->configure(-state => 'normal');
  54.    
  55.     # 插入新内容
  56.     $text->insert('end', $content);
  57.    
  58.     # 限制行数
  59.     my $line_count = $text->index('end');
  60.     $line_count =~ s/\..*//;
  61.     if ($line_count > $MAX_LINES) {
  62.         my $delete_lines = $line_count - $MAX_LINES;
  63.         # 删除最旧的行(保留最新的MAX_LINES行)
  64.         eval {
  65.             $text->delete('1.0', "${delete_lines}.0");
  66.         };
  67.     }
  68.    
  69.     # 更新状态标签
  70.     my $current_lines = $text->index('end');
  71.     $current_lines =~ s/\..*//;
  72.     $status_label->configure(-text => "行数: $current_lines (最大: $MAX_LINES)");
  73.    
  74.     # 禁用编辑并滚动到底部
  75.     $text->configure(-state => 'disabled');
  76.     $text->see('end');
  77. }

  78. # 在显示区域插入初始内容
  79. sub display_content {
  80.     # 启用编辑
  81.     $text->configure(-state => 'normal');
  82.    
  83.     # 插入一些文字
  84.     $text->insert('end', "图片显示测试:\n");
  85.     $text->insert('end', "第一张图片:\n");
  86.    
  87.     # 尝试加载并显示图片
  88.     eval {
  89.         my $img = $mw->Photo(-file => '20260421071250802.bmp');
  90.         $text->imageCreate('end', -image => $img);
  91.         $text->insert('end', "\n");
  92.     };
  93.     if ($@) {
  94.         $text->insert('end', "无法加载图片: 20260421071250802.bmp (错误: $@)\n");
  95.     }
  96.    
  97.     $text->insert('end', "\n第二张图片:\n");
  98.     eval {
  99.         my $img1 = $mw->Photo(-file => '1.gif');
  100.         $text->imageCreate('end', -image => $img1);
  101.         $text->insert('end', "\n");
  102.     };
  103.     if ($@) {
  104.         $text->insert('end', "无法加载图片: 1.gif (错误: $@)\n");
  105.     }
  106.    
  107.     # 禁用编辑并滚动到底部
  108.     $text->configure(-state => 'disabled');
  109.     $text->see('end');
  110. }

  111. # 显示帮助信息
  112. sub show_help {
  113.     my $content = '';
  114.     $content .= "可用命令:\n";
  115.     $content .= "  test     - 显示测试内容(图文混排)\n";
  116.     $content .= "  help     - 显示此帮助信息\n";
  117.     $content .= "  clear    - 清空显示区域\n";
  118.     $content .= "  text [内容] - 显示自定义文字\n";
  119.     $content .= "  echo [内容] - 显示回显内容\n";
  120.     $content .= "  tu       - 显示图片测试\n";
  121.     $content .= "  exit     - 退出程序\n";
  122.     $content .= "\n输入命令后按回车执行\n";
  123.    
  124.     insert_with_limit($content);
  125. }

  126. # 清空显示区域
  127. sub clear_display {
  128.     $text->configure(-state => 'normal');
  129.     $text->delete('1.0', 'end');
  130.     $text->configure(-state => 'disabled');
  131.     $status_label->configure(-text => "行数: 0 (最大: $MAX_LINES)");
  132. }

  133. # 显示自定义文本
  134. sub show_text {
  135.     my ($content) = @_;
  136.     insert_with_limit("$content\n");
  137. }

  138. # 显示图片测试 - 修正版本
  139. sub tu {
  140.     # 启用编辑
  141.     $text->configure(-state => 'normal');
  142.    
  143.     $text->insert('end', "=== 图片测试 ===\n");
  144.    
  145.     # 测试加载第一张图片
  146.     $text->insert('end', "加载图片 20260421071250802.bmp:\n");
  147.     eval {
  148.         my $img2 = $mw->Photo(-file => '20260421071250802.bmp');
  149.         $text->imageCreate('end', -image => $img2);
  150.         $text->insert('end', "\n");
  151.     };
  152.     if ($@) {
  153.         $text->insert('end', "错误: 无法加载 20260421071250802.bmp - $@\n");
  154.     }
  155.    
  156.     $text->insert('end', "\n加载图片 1.gif:\n");
  157.     eval {
  158.         my $img3 = $mw->Photo(-file => '1.gif');
  159.         $text->imageCreate('end', -image => $img3);
  160.         $text->insert('end', "\n");
  161.     };
  162.     if ($@) {
  163.         $text->insert('end', "错误: 无法加载 1.gif - $@\n");
  164.     }
  165.    
  166.     $text->insert('end', "=== 图片测试结束 ===\n");
  167.    
  168.     # 禁用编辑并滚动到底部
  169.     $text->configure(-state => 'disabled');
  170.     $text->see('end');
  171. }

  172. # 处理命令
  173. sub process_command {
  174.     my $command = $input->get();
  175.     $input->delete(0, 'end');
  176.    
  177.     # 移除前后空格
  178.     $command =~ s/^\s+//;
  179.     $command =~ s/\s+$//;
  180.    
  181.     # 处理空命令
  182.     if ($command eq '') { return; }

  183.     # 在显示区域显示输入的命令
  184.     insert_with_limit("> $command\n");
  185.    
  186.     # 解析命令
  187.     if ($command eq 'exit' || $command eq 'quit') { exit(0); }
  188.     elsif ($command eq 'help')  { show_help();       }
  189.     elsif ($command eq 'clear') { clear_display();   }
  190.     elsif ($command eq 'tu') { tu();   }
  191.     elsif ($command eq 'test')  { display_content(); }
  192.     elsif ($command =~ /^echo\s+(.+)/) {        show_text($1);    }
  193.     elsif ($command =~ /^text\s+(.+)/) {        show_text($1);    }
  194.     else {insert_with_limit("未知命令: $command (输入 'help' 查看可用命令)\n");    }
  195. }

  196. # 设置焦点到输入框
  197. $input->focus();

  198. # 初始化显示内容
  199. # 改为显示帮助信息,让用户知道如何使用
  200. show_help();

  201. # 进入主循环
  202. MainLoop;
复制代码
输入tu,可以显示对应的图片。需要一种匹配比较选择的正则图文输出,还有gif是静态显示第一页,不是播放动图。
 楼主| 发表于 2026-6-27 16:57:52 | 显示全部楼层
本帖最后由 zzz19760225 于 2026-6-30 20:45 编辑

模仿cmd界面的perl问答输入输出页面
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use utf8;
  5. use Encode;
  6. use Tk;
  7. use Tk::ROText;

  8. # Linux系统使用UTF-8编码
  9. binmode(STDOUT, ':encoding(utf8)');
  10. binmode(STDIN, ':encoding(utf8)');
  11. binmode(STDERR, ':encoding(utf8)');

  12. my $mw = MainWindow->new;
  13. $mw->title("智能命令行 - 支持图片显示");
  14. $mw->geometry("800x600");

  15. my $main_frame = $mw->Frame->pack(-fill => 'both', -expand => 1);

  16. my $output = $main_frame->Scrolled('ROText',
  17.     -scrollbars => 'e',
  18.     -wrap => 'word',
  19.     -font => ['Courier', 10],
  20.     -background => 'black',
  21.     -foreground => 'lime',
  22. )->pack(-fill => 'both', -expand => 1, -side => 'top');

  23. my $input_frame = $main_frame->Frame->pack(-fill => 'x', -side => 'bottom');
  24. my $prompt = $input_frame->Label(
  25.     -text => '> ',
  26.     -font => ['Courier', 10],
  27.     -background => 'black',
  28.     -foreground => 'lime',
  29. )->pack(-side => 'left');

  30. my $input = $input_frame->Entry(
  31.     -font => ['Courier', 10],
  32.     -background => 'black',
  33.     -foreground => 'lime',
  34.     -insertbackground => 'lime',
  35.     -width => 80,
  36. )->pack(-side => 'left', -fill => 'x', -expand => 1);

  37. my $send_btn = $input_frame->Button(
  38.     -text => '发送',
  39.     -command => \&process_command,
  40.     -background => 'gray30',
  41.     -foreground => 'white',
  42. )->pack(-side => 'right');

  43. $input->bind('<Return>' => \&process_command);

  44. my @history;
  45. my $history_index = -1;

  46. sub insert_chinese {
  47.     my ($text) = @_;
  48.     $output->insert('end', $text);
  49. }

  50. # 显示欢迎信息
  51. insert_chinese("=" x 60 . "\n");
  52. insert_chinese("智能命令行系统 v1.0\n");
  53. insert_chinese("支持命令:\n");
  54. insert_chinese("  help     - 显示帮助\n");
  55. insert_chinese("  clear    - 清屏\n");
  56. insert_chinese("  image    - 显示示例图片\n");
  57. insert_chinese("  text [内容] - 显示文本\n");
  58. insert_chinese("  date     - 显示当前日期时间\n");
  59. insert_chinese("  calc [表达式] - 计算数学表达式\n");
  60. insert_chinese("  echo [内容] - 回显文本\n");
  61. insert_chinese("=" x 60 . "\n\n");

  62. # 关键修复:确保滚动到顶部
  63. $output->see('1.0');

  64. # 多个延迟确保显示正确
  65. $mw->after(50, sub { $output->see('1.0'); });
  66. $mw->after(200, sub { $output->see('1.0'); });

  67. sub process_command {
  68.     my $command = $input->get();
  69.     $input->delete(0, 'end');
  70.    
  71.     push @history, $command if $command ne '';
  72.     $history_index = -1;
  73.    
  74.     insert_chinese("\n> $command\n");
  75.    
  76.     if ($command eq 'help') {
  77.         show_help();
  78.     }
  79.     elsif ($command eq 'clear') {
  80.         $output->delete('1.0', 'end');
  81.         insert_chinese("屏幕已清空\n");
  82.     }
  83.     elsif ($command eq 'image') {
  84.         show_demo_image();
  85.     }
  86.     elsif ($command =~ /^text\s+(.+)/) {
  87.         insert_chinese("$1\n");
  88.     }
  89.     elsif ($command eq 'date') {
  90.         insert_chinese(scalar(localtime) . "\n");
  91.     }
  92.     elsif ($command =~ /^calc\s+(.+)/) {
  93.         eval_calculation($1);
  94.     }
  95.     elsif ($command =~ /^echo\s+(.+)/) {
  96.         insert_chinese("$1\n");
  97.     }
  98.     else {
  99.         insert_chinese("未知命令: $command (输入 'help' 查看帮助)\n");
  100.     }
  101.    
  102.     $output->see('end');
  103. }

  104. sub show_help {
  105.     insert_chinese("\n可用命令:\n");
  106.     insert_chinese("  help           - 显示此帮助信息\n");
  107.     insert_chinese("  clear          - 清空输出区域\n");
  108.     insert_chinese("  image          - 显示示例图片\n");
  109.     insert_chinese("  text <内容>    - 在输出区域显示文本\n");
  110.     insert_chinese("  date           - 显示当前日期和时间\n");
  111.     insert_chinese("  calc <表达式>  - 计算数学表达式\n");
  112.     insert_chinese("  echo <内容>    - 回显文本\n");
  113.     insert_chinese("\n");
  114. }

  115. sub show_demo_image {
  116.     my $canvas_window = $mw->Toplevel();
  117.     $canvas_window->title("图片显示窗口");
  118.     $canvas_window->geometry("400x300");
  119.    
  120.     my $canvas = $canvas_window->Canvas(
  121.         -background => 'white',
  122.         -width => 400,
  123.         -height => 300,
  124.     )->pack(-fill => 'both', -expand => 1);
  125.    
  126.     $canvas->createRectangle(50, 50, 150, 150,
  127.         -fill => 'red',
  128.         -outline => 'black',
  129.         -width => 2,
  130.     );
  131.    
  132.     $canvas->createOval(200, 50, 300, 150,
  133.         -fill => 'blue',
  134.         -outline => 'black',
  135.         -width => 2,
  136.     );
  137.    
  138.     $canvas->createPolygon(50, 200, 150, 200, 100, 100,
  139.         -fill => 'green',
  140.         -outline => 'black',
  141.         -width => 2,
  142.     );
  143.    
  144.     $canvas->createText(250, 200,
  145.         -text => '示例图形',
  146.         -font => ['Arial', 16],
  147.         -fill => 'purple',
  148.     );
  149.    
  150.     insert_chinese("已在新窗口中显示示例图片\n");
  151. }

  152. sub eval_calculation {
  153.     my ($expr) = @_;
  154.     $expr =~ s/\s+//g;
  155.    
  156.     if ($expr !~ /^[\d+\-*\/\(\)\.]+$/) {
  157.         insert_chinese("错误: 表达式包含非法字符\n");
  158.         return;
  159.     }
  160.    
  161.     eval {
  162.         my $result = eval $expr;
  163.         if ($@) {
  164.             insert_chinese("计算错误: $@\n");
  165.         } else {
  166.             insert_chinese("$expr = $result\n");
  167.         }
  168.     };
  169. }

  170. $input->bind('<Up>' => sub {
  171.     if ($history_index < @history - 1) {
  172.         $history_index++;
  173.         $input->delete(0, 'end');
  174.         $input->insert(0, $history[-1 - $history_index]);
  175.     }
  176. });

  177. $input->bind('<Down>' => sub {
  178.     if ($history_index > 0) {
  179.         $history_index--;
  180.         $input->delete(0, 'end');
  181.         $input->insert(0, $history[-1 - $history_index]);
  182.     } elsif ($history_index == 0) {
  183.         $history_index = -1;
  184.         $input->delete(0, 'end');
  185.     }
  186. });

  187. $input->focus();

  188. # 最终修复:在窗口完全显示后滚动到顶部
  189. $mw->after(500, sub {
  190.     $output->see('1.0');
  191.     $mw->update();
  192. });

  193. MainLoop;
复制代码
运行后:
  1. ============================================================
  2. 智能命令行系统 v1.0
  3. 支持命令:
  4.   help     - 显示帮助
  5.   clear    - 清屏
  6.   image    - 显示示例图片
  7.   text [内容] - 显示文本
  8.   date     - 显示当前日期时间
  9.   calc [表达式] - 计算数学表达式
  10.   echo [内容] - 回显文本
  11. ============================================================
  12. >                          发送
复制代码
deepseek这个作品,形式和颜色是满足需求的。就是中文显示的行里,中文头部被掩盖了一部分。怎么将病症,证候,治法,人物信息装进去,加上增减量和存量,奖罚什么的。老毛病,依然对程序内容看都不看,有了就好了。这样和官僚有什么差别呢,不知道有什么。
要有文字和图片,可能用perl Tk text,Tk模块和text组件。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-7-17 00:45

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表