Perl Tk:帮助我修复文本编辑器中的突出显示
因此,我正在用Perl Tk编写一个文本编辑器,我有一个用于高亮显示的子例程,它插入两个高亮显示的空格供您键入 我有三个问题Perl Tk:帮助我修复文本编辑器中的突出显示,perl,tk,Perl,Tk,因此,我正在用Perl Tk编写一个文本编辑器,我有一个用于高亮显示的子例程,它插入两个高亮显示的空格供您键入 我有三个问题 当高亮显示子例程被触发时,我希望光标移动到左1空间。这样,当插入高亮显示或下划线样式时,光标自动位于两个空格之间,用户可以立即键入该样式,而无需使用左箭头键。我想我的问题是如何在光标处而不是在文件末尾插入样式 子例程的文本格式未正确保存到文件类型。我目前正在使用.rtf 我想实现一个下拉式字体选择菜单,从系统字体列表中提取,但我不确定如何实现 #/usr/local/bi
#/usr/local/bin/perl
#!/C:/Perl/site/lib
使用传统知识;
使用utf8;
使用变量qw/$TOP/;
#主窗口
my$mw=新的主窗口;
#创建文本区域
my$txt=$mw->Scrolled('Text',-width=>50,-scrollbars=>e')->pack(),-setgrid=>true;
#声明有菜单
我的$mbar=$mw->Menu();
$mw->configure(-menu=>$mbar);
#主按钮
my$file=$mbar->cascade(-label=>“file”,-underline=>0,-tearoff=>0);
my$others=$mbar->cascade(-label=>“others”,-underline=>0,-tearoff=>0);
my$help=$mbar->cascade(-label=>“help”,-underline=>0,-tearoff=>0);
##文件菜单##
$file->command(-label=>“New”,-underline=>0,
-command=>sub{$txt->delete('1.0','end');});
$file->checkbutton(-label=>“Open”,-underline=>0,
-命令=>[\&openfunction,“Open”];
$file->command(-label=>“Save”,-underline=>0,
-命令=>[\&savefunction,“Save”];
$file->separator();
$file->command(-label=>“Exit”,-underline=>1,
-command=>sub{exit});
##其他菜单##
my$insert=$others->cascade(-label=>“insert”,-underline=>0,-tearoff=>0);
$insert->command(-label=>“Highlight”,
-命令=>[\&highlight,“highlight”];
$insert->command(-label=>“下划线”,
-命令=>[\&underline,“underline”];
$insert->command(-label=>“Title”,
-命令=>[\&粗体,“标题”];
$insert->command(-label=>“点画”,
-命令=>[\&点画,“点画”];
$insert->command(-label=>“查找和替换”,
-命令=>[\&find\u replace,“find&replace”];
$insert->command(-label=>“名称”,
-command=>sub{$txt->insert('end',“Name:Thaddeus-Roebuck-Badgercock\n”);});
$insert->command(-label=>“Bullet Point”,-command=>sub{
$txt->insert('结束',“⚫\t“;});
$insert->command(-label=>“电子邮件”,
-command=>sub{$txt->insert('end',“E-Mail:\n”);});
$others->command(-label=>“全部插入”,-underline=>7,
-command=>sub{$txt->insert('end',“名称:Thaddeus Roebuck Badgercock
网站:
电邮:”;
});
##帮助##
$help->command(-label=>“About”,-command=>sub{
$txt->delete('1.0','end');
$txt->insert('end',
“关于
----------
这是一个用Perl-Tk编写的简单文本编辑器。该程序是在GNU公共许可下获得许可的,是免费软件。
"); });
##标签##
$txt->标记(qw/配置背景点画-背景黑色-边框宽度0
-bg点画灰12/);
$txt->tag(qw/configure bold-font C_bold/);
$txt->tag(qw/configure color1-background/=>“#a0b7ce”);
$txt->tag(qw/configure凸起-背景白色-浮雕凸起/);
$txt->tag(qw/配置凹陷-背景白色-浮雕凹陷/);
$txt->tag(qw/configure underline-underline on/);
主回路;
子查找和替换{
$txt->FindAndReplacePopUp;
}
子点画{
$txt->insert('end','','bgstipple');
}#端部样式
亚粗体{
$txt->insert('end','bold');
}
次高光{
$txt->insert('end','color1');
}
次级培养{
$txt->insert('end','raised');
}
次下划线{
$txt->insert('end','underline');#怎么做
}
子存储函数{
my$fileDataToSave=$txt->get(“1.0”,“end”);
#触发对话框
$filename=$mw->getSaveFile(-title=>“选择要保存的文件”,
-defaultextension=>'.rtf',-initialdir=>'.');
#保存文件
打开(我的$fh,“>”,$filename)或死亡$!;
打印$fh$文件数据保存;
收盘价$fh;
}
子开函数{
#“获取文件的函数”对话框
$filename=$mw->getOpenFile(-title=>“选择要加载的文件”,
-defaultextension=>'.txt',-initialdir=>'.');
#函数将文件加载到字符串中,例如,如果您使用use file::Slurp
打开($fh,您可以使用以下命令在当前光标位置插入高亮显示格式:
sub highlight {
$txt->insert('insert', ' ', 'color1');
$txt->SetCursor( 'insert - 1 chars' ); # <-- moves the cursor back into the
# hightlight region
}
子高亮显示{
$txt->insert('insert','color1');
$txt->SetCursor('insert-1 chars');#您可以使用以下命令在当前光标位置插入突出显示格式:
sub highlight {
$txt->insert('insert', ' ', 'color1');
$txt->SetCursor( 'insert - 1 chars' ); # <-- moves the cursor back into the
# hightlight region
}
子高亮显示{
$txt->insert('insert','color1');
$txt->SetCursor('insert-1个字符')##你能提供一个吗?我相信如果安装了Tk,当前的示例是可复制的FindAndReplacePopUp
?在这一行$txt->FindAndReplacePopUp
不支持以RTF格式保存Tk,请参阅问题。要获得一个漂亮的字体对话框,请参阅你能提供一个吗?我相信当前的示例是可复制的,如果您已经安装了Tk什么是FindAndReplacePopUp
?在这一行$txt->FindAndReplacePopUp
不支持以RTF格式保存Tk,请参阅问题。有关漂亮的字体对话框,请参阅