• <bdo id='SUBX0'></bdo><ul id='SUBX0'></ul>
      <tfoot id='SUBX0'></tfoot><legend id='SUBX0'><style id='SUBX0'><dir id='SUBX0'><q id='SUBX0'></q></dir></style></legend>
    1. <small id='SUBX0'></small><noframes id='SUBX0'>

      <i id='SUBX0'><tr id='SUBX0'><dt id='SUBX0'><q id='SUBX0'><span id='SUBX0'><b id='SUBX0'><form id='SUBX0'><ins id='SUBX0'></ins><ul id='SUBX0'></ul><sub id='SUBX0'></sub></form><legend id='SUBX0'></legend><bdo id='SUBX0'><pre id='SUBX0'><center id='SUBX0'></center></pre></bdo></b><th id='SUBX0'></th></span></q></dt></tr></i><div id='SUBX0'><tfoot id='SUBX0'></tfoot><dl id='SUBX0'><fieldset id='SUBX0'></fieldset></dl></div>

        使用 Tk Grid Geometry Manager 的 GUI 布局

        GUI layout using Tk Grid Geometry Manager(使用 Tk Grid Geometry Manager 的 GUI 布局)

            <bdo id='9oj3I'></bdo><ul id='9oj3I'></ul>
              <tbody id='9oj3I'></tbody>
            <i id='9oj3I'><tr id='9oj3I'><dt id='9oj3I'><q id='9oj3I'><span id='9oj3I'><b id='9oj3I'><form id='9oj3I'><ins id='9oj3I'></ins><ul id='9oj3I'></ul><sub id='9oj3I'></sub></form><legend id='9oj3I'></legend><bdo id='9oj3I'><pre id='9oj3I'><center id='9oj3I'></center></pre></bdo></b><th id='9oj3I'></th></span></q></dt></tr></i><div id='9oj3I'><tfoot id='9oj3I'></tfoot><dl id='9oj3I'><fieldset id='9oj3I'></fieldset></dl></div>

              <small id='9oj3I'></small><noframes id='9oj3I'>

            1. <legend id='9oj3I'><style id='9oj3I'><dir id='9oj3I'><q id='9oj3I'></q></dir></style></legend>
                  <tfoot id='9oj3I'></tfoot>

                  本文介绍了使用 Tk Grid Geometry Manager 的 GUI 布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  使用 Python 构建一个供个人使用的小型应用程序,并认为我会尝试使用 Tkinter 进行一些 GUI 编程.这是我目前创建的 GUI:

                  Building a small application for personal use with Python and thought I'd try my hand with a little GUI programming using Tkinter. This is the GUI I've created so far:

                  应用疑惑:

                  如何确保屏幕截图中的三个 LableFrame(A、B 和 C)具有相同的宽度?(或者更确切地说,宽度等于三个中最宽的那个?例如,在屏幕截图中,A 是最宽的,我希望 B 和 C 也一样宽 - 直到 D 行).

                  How can I make sure that the three LableFrames - A, B and C in the screenshot - have the same width? (Or rather, have the width equal to the widest of the three? For example, in the screenshot, A is the widest and I'd like B and C to also be as wide - up to the line D).

                  (不必动态计算 - 如果我能确保在第一次编码时宽度相同就足够了.它们不需要在运行时更改.)

                  (It doesn't have to dynamically calculated - it is enough if I can ensure that the width are the same when I code it, the first time round. They don't need to change on runtime.)

                  Tk Grid Geometry Manager 疑惑:

                  1. 当您使用框架时,网格(行、列)是仅特定于框架的大小还是根据窗体(根窗口)的大小计算得出的?

                  1. When you use frames, is the grid (row, column) specific to only the size of the frame or is it calculated based on the size of the form (root window)?

                  网格中列的大小如何确定?

                  How is the size of a column determined in a grid?

                  Python GUI 代码:

                  import Tkinter
                  
                  if __name__ == '__main__':
                      form = Tkinter.Tk()
                  
                      getFld = Tkinter.IntVar()
                  
                      form.wm_title('File Parser')
                  
                      stepOne = Tkinter.LabelFrame(form, text=" 1. Enter File Details: ")
                      stepOne.grid(row=0, columnspan=7, sticky='W', 
                                   padx=5, pady=5, ipadx=5, ipady=5)
                  
                      helpLf = Tkinter.LabelFrame(form, text=" Quick Help ")
                      helpLf.grid(row=0, column=9, columnspan=2, rowspan=8, 
                                  sticky='NS', padx=5, pady=5)
                      helpLbl = Tkinter.Label(helpLf, text="Help will come - ask for it.")
                      helpLbl.grid(row=0)
                  
                      stepTwo = Tkinter.LabelFrame(form, text=" 2. Enter Table Details: ")
                      stepTwo.grid(row=2, columnspan=7, sticky='W', 
                                   padx=5, pady=5, ipadx=5, ipady=5)
                  
                      stepThree = Tkinter.LabelFrame(form, text=" 3. Configure: ")
                      stepThree.grid(row=3, columnspan=7, sticky='W', 
                                     padx=5, pady=5, ipadx=5, ipady=5)
                  
                      inFileLbl = Tkinter.Label(stepOne, text="Select the File:")
                      inFileLbl.grid(row=0, column=0, sticky='E', padx=5, pady=2)
                  
                      inFileTxt = Tkinter.Entry(stepOne)
                      inFileTxt.grid(row=0, column=1, columnspan=7, sticky="WE", pady=3)
                  
                      inFileBtn = Tkinter.Button(stepOne, text="Browse ...")
                      inFileBtn.grid(row=0, column=8, sticky='W', padx=5, pady=2)
                  
                      outFileLbl = Tkinter.Label(stepOne, text="Save File to:")
                      outFileLbl.grid(row=1, column=0, sticky='E', padx=5, pady=2)
                  
                      outFileTxt = Tkinter.Entry(stepOne)
                      outFileTxt.grid(row=1, column=1, columnspan=7, sticky="WE", pady=2)
                  
                      outFileBtn = Tkinter.Button(stepOne, text="Browse ...")
                      outFileBtn.grid(row=1, column=8, sticky='W', padx=5, pady=2)
                  
                      inEncLbl = Tkinter.Label(stepOne, text="Input File Encoding:")
                      inEncLbl.grid(row=2, column=0, sticky='E', padx=5, pady=2)
                  
                      inEncTxt = Tkinter.Entry(stepOne)
                      inEncTxt.grid(row=2, column=1, sticky='E', pady=2)
                  
                      outEncLbl = Tkinter.Label(stepOne, text="Output File Encoding:")
                      outEncLbl.grid(row=2, column=5, padx=5, pady=2)
                  
                      outEncTxt = Tkinter.Entry(stepOne)
                      outEncTxt.grid(row=2, column=7, pady=2)
                  
                      outTblLbl = Tkinter.Label(stepTwo, 
                            text="Enter the name of the table to be used in the statements:")
                      outTblLbl.grid(row=3, column=0, sticky='W', padx=5, pady=2)
                  
                      outTblTxt = Tkinter.Entry(stepTwo)
                      outTblTxt.grid(row=3, column=1, columnspan=3, pady=2, sticky='WE')
                  
                      fldLbl = Tkinter.Label(stepTwo, 
                                             text="Enter the field (column) names of the table:")
                      fldLbl.grid(row=4, column=0, padx=5, pady=2, sticky='W')
                  
                      getFldChk = Tkinter.Checkbutton(stepTwo, 
                                             text="Get fields automatically from input file",
                                             onvalue=1, offvalue=0)
                      getFldChk.grid(row=4, column=1, columnspan=3, pady=2, sticky='WE')
                  
                      fldRowTxt = Tkinter.Entry(stepTwo)
                      fldRowTxt.grid(row=5, columnspan=5, padx=5, pady=2, sticky='WE')
                  
                      transChk = Tkinter.Checkbutton(stepThree, 
                                 text="Enable Transaction", onvalue=1, offvalue=0)
                      transChk.grid(row=6, sticky='W', padx=5, pady=2)
                  
                      transRwLbl = Tkinter.Label(stepThree, 
                                   text=" => Specify number of rows per transaction:")
                      transRwLbl.grid(row=6, column=2, columnspan=2, 
                                      sticky='W', padx=5, pady=2)
                  
                      transRwTxt = Tkinter.Entry(stepThree)
                      transRwTxt.grid(row=6, column=4, sticky='WE')
                  
                      form.mainloop()
                  

                  (注意:对于 Python 2.4.3)

                  (Note: For Python 2.4.3)

                  推荐答案

                  如果您使用相同的列跨度并在所有三个 LabelFrame 上使用sticky='WE',那么它们应该具有相同的宽度.例如,您想使用

                  If you use the same columnspan and use sticky='WE' on all three LabelFrames then they should have the same width. For example, you want to use

                  stepTwo = Tkinter.LabelFrame(form, text=" 2. Enter Table Details: ")
                  stepTwo.grid(row=2, columnspan=7, sticky='WE', 
                               padx=5, pady=5, ipadx=5, ipady=5)
                  

                  问题

                  1) 当您使用框架时,网格(行、列)是否仅特定于框架的大小还是根据表单的大小计算得出(根窗口)?

                  1) When you use frames, is the grid (row, column) specific to only the size of the frame or is it calculated based on the size of the form (root window)?

                  这里是相互依赖的.表单的首选大小将取决于子项和布局的首选大小,但子项的实际大小将取决于表单和布局的实际大小.布局是从孩子到根来确定首选大小,然后当它到达根时,首选大小用作实际大小(除非被覆盖).然后布局返回分配实际尺寸.

                  There is an interdependence here. The preferred size of the form will depend on the preferred sizes of the children and the layout, but the actual sizes of the children will depend on the actual size of the form and the layout. Layout is done from the children to the root to determine the preferred sizes, and then when it gets to the root, the preferred size is used as the actual size (unless overridden). Layout then goes back down assigning actual sizes.

                  2) 网格中列的大小如何确定?

                  2) How is the size of a column determined in a grid?

                  列的首选大小是根据该行中所有项目的最小首选宽度确定的.列的实际大小由首选大小加上父窗口小部件额外空间的一定百分比确定.

                  The preferred size of a column is determined based to be the minimum preferred width of all the items in that row. The actual size of the column is determined by the preferred size plus some percentage of the extra space of the parent widget.

                  3) 我还没有完全理解权重"在网格中的作用.什么时候应该用吗?

                  3) I haven't fully understood what 'weight' does within a grid. When should it be used?

                  权重决定了我上面提到的额外空间的百分比.给列的额外空间量是 column_weight/total_weight.

                  The weight determines the percentage of extra space that I mentioned above. The amount of the extra space given to the column is column_weight/total_weight.

                  这篇关于使用 Tk Grid Geometry Manager 的 GUI 布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Pythonic and efficient way of finding adjacent cells in grid(在网格中查找相邻单元格的 Pythonic 和有效方法)
                  map a hexagonal grid in matplotlib(在 matplotlib 中映射六边形网格)
                  Execute arbitrary python code remotely - can it be done?(远程执行任意 python 代码 - 可以吗?)
                  Python - Plotting colored grid based on values(Python - 根据值绘制彩色网格)
                  Is there a GUI design app for the Tkinter / grid geometry?(是否有 Tkinter/网格几何图形的 GUI 设计应用程序?)
                  tkinter Canvas Scrollbar with Grid?(带有网格的 tkinter 画布滚动条?)

                    <small id='sqjUy'></small><noframes id='sqjUy'>

                          <tbody id='sqjUy'></tbody>
                          <bdo id='sqjUy'></bdo><ul id='sqjUy'></ul>

                        • <tfoot id='sqjUy'></tfoot><legend id='sqjUy'><style id='sqjUy'><dir id='sqjUy'><q id='sqjUy'></q></dir></style></legend>
                          • <i id='sqjUy'><tr id='sqjUy'><dt id='sqjUy'><q id='sqjUy'><span id='sqjUy'><b id='sqjUy'><form id='sqjUy'><ins id='sqjUy'></ins><ul id='sqjUy'></ul><sub id='sqjUy'></sub></form><legend id='sqjUy'></legend><bdo id='sqjUy'><pre id='sqjUy'><center id='sqjUy'></center></pre></bdo></b><th id='sqjUy'></th></span></q></dt></tr></i><div id='sqjUy'><tfoot id='sqjUy'></tfoot><dl id='sqjUy'><fieldset id='sqjUy'></fieldset></dl></div>