使用网格在单元格中放置两个相邻的单选按钮

Placing two radio buttons adjacent in the cell using grid

我想在网格单元格中放置两个相邻的单选按钮。

如何做到这一点?

实例化一个新的框架,将这个框架放在使用网格的单元格中。然后你可以实例化两个单选按钮并在框架中将它们网格化。

package requite Tk

ttk::label .c11 -text "Cell 1 1"
ttk::label .c12 -text "Cell 1 2"
ttk::label .c13 -text "Cell 1 3"
grid .c11 -row 0 -column 0
grid .c12 -row 0 -column 1
grid .c13 -row 0 -column 2

ttk::label .c21     -text "Cell 2 1"
ttk::frame .frame 
ttk::label .c23     -text "Cell 2 3"
grid .c21   -row 1 -column 0
grid .frame -row 1 -column 1
grid .c23   -row 1 -column 2

    ttk::radiobutton  .frame.rb1 -text "Rb1"
    ttk::radiobutton  .frame.rb2 -text "Rb2"
    grid    .frame.rb1   -row 0 -column 0
    grid    .frame.rb2   -row 0 -column 1

ttk::label .c31 -text "Cell 3 1"
ttk::label .c32 -text "Cell 3 2"
ttk::label .c33 -text "Cell 3 3"
grid .c31 -row 2 -column 0
grid .c32 -row 2 -column 1
grid .c33 -row 2 -column 2

这是 NoonanRosenblum 的回答,不是我的;我只是想就此提出两点意见,但我无法将它们放入评论中。

  1. grid 放置不必像 NoonanRosenblum 的示例中那样冗长。
  2. 单选按钮小部件需要分配不同的值才能按设计工作。如果未分配,两个按钮将作为一个按钮作出反应。

ttk::label .c11 -text "Cell 1 1"
ttk::label .c12 -text "Cell 1 2"
ttk::label .c13 -text "Cell 1 3"
grid .c11 .c12 .c13 

ttk::label .c21 -text "Cell 2 1"
ttk::frame .frame 
ttk::label .c23 -text "Cell 2 3"
grid .c21 .frame .c23   

ttk::radiobutton .frame.rb1 -text Rb1 -value 1
ttk::radiobutton .frame.rb2 -text Rb2 -value 2
grid .frame.rb1 .frame.rb2   

ttk::label .c31 -text "Cell 3 1"
ttk::label .c32 -text "Cell 3 2"
ttk::label .c33 -text "Cell 3 3"
grid .c31 .c32 .c33