Yash
Yash

Reputation: 23

Want to open tcl/tk code in single window

I want to run following tcl/tk code in single window, but when I run the below using wish yep.tcl it opens two windows as in picture below. I want only one window i.e okie

1

What changes are required?

proc yep {} {
    toplevel .t
    wm geometry .t 300x200-5+40
    wm title .t "okie"
    label .t.n -text "CELL"
    grid .t.n -rowspan 2 -columnspan 5
}
yep

Upvotes: 1

Views: 273

Answers (2)

Donal Fellows
Donal Fellows

Reputation: 137567

You're creating another toplevel window, .t, in addition to the default one called .. To work with only a single window, either use the default one or withdraw the default one.

Using the default

proc yep {} {
    wm geometry . 300x200-5+40
    wm title . "okie"
    label .n -text "CELL"
    grid .n -rowspan 2 -columnspan 5
}
yep

Withdrawing the default

proc yep {} {
    toplevel .t
    wm geometry .t 300x200-5+40
    wm title .t "okie"
    label .t.n -text "CELL"
    grid .t.n -rowspan 2 -columnspan 5

    # Hide the unwanted window
    wm withdraw .
    # Make the application go away when we close the visible window
    wm protocol .t WM_DELETE_WINDOW { exit }
}
yep

Upvotes: 2

Peter Lewerin
Peter Lewerin

Reputation: 13252

The command toplevel creates an extra window. If you just want to use the main window, skip the invocation of toplevel and use . instead of .t. (.t.n becomes .n, of course.)

Upvotes: 1

Related Questions