Yash
Yash

Reputation: 23

Not able to move button in tcl/tk

GUI snapshot In this code i want to move new_button to right most side.But After changing row, column,columnspan also,it stays there only. What are the changes required in code.

ttk::frame .c
.c configure -borderwidth 7 -relief groove -padding "200 25"
button .c.cancle -text cancel -command {destroy .}
ttk::label .c.l -text "yash"
ttk::checkbutton .c.one -text One -variable oe -onvalue 1
ttk::button .c.ok -text Okay -command sp12
button .c.lop -text New_button

grid .c -column 0 -row 4
grid .c.l -column 0 -row 1 -columnspan 2
grid .c.one -column 0 -row 3 -columnspan 2
grid .c.ok -column 3 -row 3 -columnspan 2
grid .c.cancle -column 9 -row 3 -columnspan 2
grid .c.lop -column 30 -row 10 -rowspan 10 -columnspan 15 -sticky w

Upvotes: 0

Views: 372

Answers (1)

Jerry
Jerry

Reputation: 71578

grid can be tricky. If there are no widgets in one of the rows or columns, that row and/or column will be considered to have 0 width and/or 0 height. Thus increasing the row number and/or column number will not change anything.

In your current script, the padding to the frame prevents the widgets inside the .c grid to be near the .c border (padding adds a 'layer' of space between the border and the widgets inside it). So this is the first thing to remove. Once done, the widget will lose its size though, because the size of the widget depend on the size of the widgets inside it after all.

So a workaround here would be to define the minimum sizes:

ttk::frame .c
.c configure -borderwidth 7 -relief groove
wm minsize . 656 135  # Set a minimum size here
button .c.cancle -text cancel -command {destroy .}
ttk::label .c.l -text "yash"
ttk::checkbutton .c.one -text One -variable oe -onvalue 1
ttk::button .c.ok -text Okay -command sp12
button .c.lop -text New_button

# I cleaned up the columns
grid .c -row 0 -column 0 -sticky nsew # make it anchor all positions
grid .c.l -column 1 -row 1
grid .c.one -column 1 -row 2
grid .c.ok -column 2 -row 2
grid .c.cancle -column 3 -row 2
grid .c.lop -column 4 -row 3 -sticky se # make it anchor at south east position

# make the .c grid fit to the . window
grid columnconfigure . all -minsize 635 -weight 1
grid rowconfigure . all -weight 1
# force column before column 1 and row before row 1 to have some specific size
grid columnconfigure .c 0 -minsize 200
grid rowconfigure .c 0 -minsize 30
# make the last cell fill any spaces after it, if available
grid columnconfigure .c 4 -weight 1
grid rowconfigure .c 4 -weight 1

Result:

enter image description here

Upvotes: 0

Related Questions