tkinker网格columconfigure和行配置不起作用

时间:2018-11-04 06:49:56

标签: python-3.x tkinter grid expand

您好,我需要有关configure和columconfigure行的帮助。该程序是从框架继承的tk构建的,然后是从框架继承的Notebook(tabs),然后是从笔记本继承的grid。直到笔记本,一切都在扩展我想要的方式。

我的问题是网格系统没有扩展。我在行和列中配置了权重,但无法正常工作。 1)。我不知道引用是否正确

error: switch -mcpu=cortex-a7 conflicts with -march=armv7-a switch [-Werror]

2)。由于我在前两个级别都有pack(),因此是否必须将相同的列和行配置为root?如果我需要在哪里以及如何放置它?

这是程序:

self.tabControl.columnconfigure(employee, weight = 1)

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

您正在为标签设置显式尺寸,并使用必须指定sticky='nsew'的标签来更改标签的尺寸。

然后,在对每个选项卡进行行和列配置时tabControl

我进行了相应的更改,并在笔记本和按钮中添加了填充,以使布局更加稀疏。现在,笔记本将随窗口一起扩展。我在“应用程序”框架的行配置中设置了最小高度,以便在窗口缩小时按钮不会消失。

我将所有几何形状都更改为grid(),因为当布局变得更加复杂时,它会更容易。

我评论了以下代码中的重大更改:

import tkinter as tk
from tkinter import ttk

#upper tabs
upper_tabs = ["Final", "Requests"]
tabs = {}

Employees = ["A", "B", "C", "D", "E", "F", "G", ]
Days= ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
       "Saturday", "Sunday"]

class Application(tk.Frame): #inherent from frame.
    def __init__(self, parent):
        tk.Frame.__init__(self, parent, bg="tan")
        self.parent = parent
        self.pack(fill=tk.BOTH, expand=1)
        # Configure self to fill parent when size changes
        self.rowconfigure([0,1],weight=1, minsize=40)
            # Minsize will keep row=1 at least 50 pixels high or the
            # button will disappear when the frame shrinks
        self.columnconfigure([0,1],weight=1)
        self.GUI()

    def GUI(self): #the function that runs all the GUI functions.
        self.create_tabs()
        self.buttons()
        for name in upper_tabs:
            self.create_grid(name)

####---------create grid_GUI---------------------####

    def create_tabs(self):
        self.tabControl = ttk.Notebook(self, width=1100, height=500)
        for name in upper_tabs:
            self.tab=tk.Frame(self.tabControl, bg='thistle')
            self.tabControl.add(self.tab, text=name)
            tabs[name] = self.tab
            # Set sticky to fill up available space and padding for layout
            self.tabControl.grid(row=0, column=0, padx=10, pady=10, sticky='nsew')  

    def create_grid(self, name):
        for employee in range(len(Employees)+2):
            # columnconfigure tab instead of tabControl
            tabs[name].columnconfigure(employee, weight = 1)
            for day in range(len(Days)+2):
                # rowconfigure tab instead of tabControl
                tabs[name].rowconfigure(day, weight=1)
                self.label = tk.Label(tabs[name], relief="ridge", width=12, height=3)
                # Set sticky to fill available space
                self.label.grid(row=employee, column=day, sticky='nsew')

    def buttons(self):
        self.button=tk.Button(self, text="Caluculate", bg="salmon", )
        # Adding padding for layout
        self.button.grid(row=1, column=0, padx=(0,10), pady=(0,10), sticky='e')

def main():
    root = tk.Tk()
    root.title("class basic window")
    root.config(background="LightBlue4")
    app = Application(root)
    root.mainloop()

if __name__ == '__main__':
    main()

这是您的目标吗?