Go语言和Tcl/Tk GUI库的例子1 按钮
名字不能长 · · 8226 次点击 · · 开始浏览a 用vtcl建立一个新project,然后制作界面并保存
我自己做的 如图1
b 打开vtcl产生的main.tcl文件,我们即将进行提取关于界面的代码
复制如下匹配的n行代码,
###################
# CREATING WIDGETS
###################
。。。此处省略Tcl/Tk代码n行
###################
# SETTING GEOMETRY
###################
。。。此处省略Tcl/Tk代码n行
#############################################################################
##
我复制出来的大概100多行,接着要进行删除精简
1 把第一行 到 最后一个以wm起头的行 【1-18行】之间的所有内容 删除,如下图
2 把所有以 vTcl:DefineAlias起头的行删除
3 把 -in $top 全部去掉【或者替换成 -in . 】
4 把$top全部去掉
5 把倒数第三第四行的
vTcl:FireEvent $base <<Ready>>
}
去掉
完成后如下图,大概50行,这些就是可以用在go里的界面代码 了
c 打开LiteIDE,新建一个go文件,把刚才得到的50行界面代码复制到init_script字符串常量里面,完成代码如下
main
"github.com/nsf/gothic"
init_script =
#把界面代码复制到这里,注释行使用#符号,\符号是续行符
button .but69 \
-pady 0 -text 默认
button .but70 \
-background {#0000ff} -foreground {#ffffff} -pady 0 -text 蓝背景
button .but71 \
-cursor X_cursor -pady 0 -text 光标变化
button .but73 \
-borderwidth 10 -pady 0 -text {bd 10px}
button .but74 \
-activeforeground {#ff00ff} \
-pady 0 -text 黑体28px
button .but75 \
-foreground {#ff0000} -pady 0 -text 按钮
button .but76 \
-foreground {#000000} -pady 0 -text raised
button .but77 \
-pady 0 -relief flat -text flat
button .but78 \
-pady 0 -relief groove -text groove
button .but79 \
-pady 0 -relief ridge -text ridge
button .but80 \
-pady 0 -relief sunken -text sunken
place .but69 \
-x 40 -y 30 -anchor nw -bordermode ignore
place .but70 \
-x 130 -y 30 -anchor nw -bordermode ignore
place .but71 \
-x 30 -y 120 -anchor nw -bordermode ignore
place .but73 \
-x 210 -y 105 -anchor nw -bordermode ignore
place .but74 \
-x 255 -y 15 -anchor nw -bordermode ignore
place .but75 \
-x 360 -y 120 -anchor nw -bordermode ignore
place .but76 \
-x 25 -y 320 -anchor nw -bordermode ignore
place .but77 \
-x 175 -y 275 -anchor nw -bordermode ignore
place .but78 \
-x 95 -y 275 -anchor nw -bordermode ignore
place .but79 \
-x 30 -y 275 -anchor nw -bordermode ignore
place .but80 \
-x 95 -y 320 -anchor nw -bordermode ignore
`
{
ir := gothic.NewInterpreter(init_script)
<-ir.Done
}
运行效果如下图
d 如果需要响应按钮事件,请参考库目录下的例子
我的是在C:\go\src\github.com\nsf\gothic\_examples
有疑问加站长微信联系(非本文作者)
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
关注微信- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码` - 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传
收入到我管理的专栏 新建专栏
a 用vtcl建立一个新project,然后制作界面并保存
我自己做的 如图1
b 打开vtcl产生的main.tcl文件,我们即将进行提取关于界面的代码
复制如下匹配的n行代码,
###################
# CREATING WIDGETS
###################
。。。此处省略Tcl/Tk代码n行
###################
# SETTING GEOMETRY
###################
。。。此处省略Tcl/Tk代码n行
#############################################################################
##
我复制出来的大概100多行,接着要进行删除精简
1 把第一行 到 最后一个以wm起头的行 【1-18行】之间的所有内容 删除,如下图
2 把所有以 vTcl:DefineAlias起头的行删除
3 把 -in $top 全部去掉【或者替换成 -in . 】
4 把$top全部去掉
5 把倒数第三第四行的
vTcl:FireEvent $base <<Ready>>
}
去掉
完成后如下图,大概50行,这些就是可以用在go里的界面代码 了
c 打开LiteIDE,新建一个go文件,把刚才得到的50行界面代码复制到init_script字符串常量里面,完成代码如下
main
"github.com/nsf/gothic"
init_script =
#把界面代码复制到这里,注释行使用#符号,\符号是续行符
button .but69 \
-pady 0 -text 默认
button .but70 \
-background {#0000ff} -foreground {#ffffff} -pady 0 -text 蓝背景
button .but71 \
-cursor X_cursor -pady 0 -text 光标变化
button .but73 \
-borderwidth 10 -pady 0 -text {bd 10px}
button .but74 \
-activeforeground {#ff00ff} \
-pady 0 -text 黑体28px
button .but75 \
-foreground {#ff0000} -pady 0 -text 按钮
button .but76 \
-foreground {#000000} -pady 0 -text raised
button .but77 \
-pady 0 -relief flat -text flat
button .but78 \
-pady 0 -relief groove -text groove
button .but79 \
-pady 0 -relief ridge -text ridge
button .but80 \
-pady 0 -relief sunken -text sunken
place .but69 \
-x 40 -y 30 -anchor nw -bordermode ignore
place .but70 \
-x 130 -y 30 -anchor nw -bordermode ignore
place .but71 \
-x 30 -y 120 -anchor nw -bordermode ignore
place .but73 \
-x 210 -y 105 -anchor nw -bordermode ignore
place .but74 \
-x 255 -y 15 -anchor nw -bordermode ignore
place .but75 \
-x 360 -y 120 -anchor nw -bordermode ignore
place .but76 \
-x 25 -y 320 -anchor nw -bordermode ignore
place .but77 \
-x 175 -y 275 -anchor nw -bordermode ignore
place .but78 \
-x 95 -y 275 -anchor nw -bordermode ignore
place .but79 \
-x 30 -y 275 -anchor nw -bordermode ignore
place .but80 \
-x 95 -y 320 -anchor nw -bordermode ignore
`
{
ir := gothic.NewInterpreter(init_script)
<-ir.Done
}
运行效果如下图
d 如果需要响应按钮事件,请参考库目录下的例子
我的是在C:\go\src\github.com\nsf\gothic\_examples