d - Tkd 小部件找不到行和列选项
问题描述
我正在尝试使用tkd
包和以下代码创建一个简单的 GUI 应用程序:
// modified from: https://github.com/nomad-software/tkd
import tkd.tkdapplication;
class Application : TkdApplication {
auto labellist = ["First", "Second", "Third", "Fourth", "Fifth", "Sixth", ];
override protected void initInterface() {
int ncol =0;
auto frame = new Frame(2, ReliefStyle.groove);
frame.pack(10);
foreach(lab; labellist){
auto label = new Label(frame, lab);
label.grid(row=nrow, column=0);
auto entry = new Entry(frame);
entry.grid(row=nrow, column=1);
nrow += 1;
}
auto exitButton = new Button(frame, "Exit").setCommand(&this.exitCommand).pack(10);
}
private void exitCommand(CommandArgs args) {
this.exit();
}
}
void main(string[] args){
auto app = new Application();
app.run();
}
但是,它给出了以下错误:
$ dub run
Performing "debug" build using /usr/bin/dmd for x86_64.
x11 1.0.21: target for configuration "tcltk-import" is up to date.
tcltk 8.6.5: target for configuration "library" is up to date.
tkd 1.1.12: target for configuration "library" is up to date.
tkdgui ~master: building configuration "application"...
source/app.d(15,15): Error: undefined identifier row
source/app.d(15,25): Error: undefined identifier column
source/app.d(17,15): Error: undefined identifier row
source/app.d(17,25): Error: undefined identifier column
source/app.d(18,4): Error: undefined identifier nrow
/usr/bin/dmd failed with exit code 1.
这里提到了有关网格的详细信息。行和列是要输入的有效选项。
问题出在哪里,如何解决。
解决方案
您的代码中有两个问题。这是第一个:
label.grid(row=nrow, column=0);
^^^^ ^^^^^^^
D 不支持您尝试使用的命名参数。相反,您将需要使用位置参数:
label.grid(0, nrow);
FWIW,有一些建议将命名参数添加到 D,但目前还没有使用该语言。
第二个问题是nrow
没有在任何地方定义。从 of 的存在ncol
和它无处使用的事实来看,您似乎将代码从处理列更改为处理行,并且没有更改ncol
to的名称nrow
。
推荐阅读
- java - Java Spring - 显示或列出 application.yml 中的所有属性
- java - 内部泛型类的调用方法无法识别泛型类型
- javascript - 如何使用按钮单击将行 ID 传递给 Modal
- java - 如何在 Java 中使用 MapStruct 将字符串转换为日期?
- c# - 如何异步等待加入操作并在c#中使用第二次加入?
- python - 如何使用 Python 向 Folium 中的每个 GeoJSON 多边形添加唯一的弹出窗口
- javascript - 使用 Javascript 和 jQuery 在 HREF 元素中获取输入框的值
- json - 处理带有数字字段中偶尔字符串数据的 JSON 的最佳方法?
- html - 高度为 100% 时如何阻止弹性项目溢出父项
- java - 如何在Jooq中将millis翻译为日期和按月和按年分组?