首页 > 解决方案 > 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.

这里提到了有关网格的详细信息。行和列是要输入的有效选项。

问题出在哪里,如何解决。

标签: dtk

解决方案


您的代码中有两个问题。这是第一个:

label.grid(row=nrow, column=0);
           ^^^^      ^^^^^^^

D 不支持您尝试使用的命名参数。相反,您将需要使用位置参数:

label.grid(0, nrow);

FWIW,有一些建议将命名参数添加到 D,但目前还没有使用该语言。

第二个问题是nrow没有在任何地方定义。从 of 的存在ncol和它无处使用的事实来看,您似乎将代码从处理列更改为处理行,并且没有更改ncolto的名称nrow


推荐阅读