首页 > 解决方案 > 如何使用 grid_columnconfigure Tkinter 为每一行配置不同的列?

问题描述

class RenameFrame():

    def __init__(self):
        pass

    def createRenameFrame(self, win):
        width = ((win.winfo_screenwidth() // 2) - 30)
        height = win.winfo_screenheight() - 105

        R_Frame = Frame(win, width=width, height=height, bg='#222222', highlightcolor='white',relief='solid')
        R_Frame.grid(row = 1, column = 0)
        R_Frame.grid_propagate(0)
        Grid.columnconfigure(R_Frame, 0, weight = 1)
        Grid.rowconfigure(R_Frame, 0, weight = 1)

        # The update() and update_idletask() methods are useful for processing any pending or idle tasks
        win.update_idletasks() 

        R_FrameContent = LabelFrame(R_Frame, text='Bunch Renamer', width=width, height = height, bg='#222222', fg='white',
            font=('Flux Regular', 20, 'bold'))
        R_FrameContent.grid(padx=10, pady=10, ipady=20, ipadx=20)
        R_FrameContent.grid_propagate(0)


        # R_FrameContet configurations
        Grid.columnconfigure(R_FrameContent, 1, weight = 2)



        # First Row start

        lb = Label(R_FrameContent, text='Selected Folder: ',bg='#222222', fg='white', font=('Flux Regular', 10, 'bold'),
            width='15')
        lb.grid(row=0, column=0, pady=5, padx=2)


        pathVal = StringVar()
        pathVal.set("No Folder Selected")
        entry = Entry(R_FrameContent, textvariable=pathVal, state='disabled', bd=0, relief = 'solid')
        entry.grid(row=0, column=1, padx=2, ipadx=5, ipady=2 , sticky="ew")
        # entry.grid_propagate(0)

        browseButton = Button(R_FrameContent, text = 'Browse', activebackground='tomato', activeforeground='white', bd=0, relief='solid',
            bg='tomato',fg='white', highlightbackground='tomato', font=('Flux Regular', 10, 'bold'), width=10 )
        browseButton.grid(row=0, column=2, pady=5, padx=2)

        # First Row end


        # Second Row start

        actionSelectionFrame = LabelFrame(R_FrameContent, text = 'Select Action', labelanchor = 'n', bg='#222222', fg='white',
            font=('Flux Regular', 10, 'bold'))
        actionSelectionFrame.grid(row = 1, column = 0, columnspan = 3, padx=15, pady= 5)


        status = IntVar()   
        rb1 = Radiobutton(actionSelectionFrame, text='Default Prefix', variable=status, font=('Flux Regular', 10, 'bold'), value= 1)
        rb1.grid(row=0, column=0, ipady=5, ipadx=5, padx=5, pady=(10, 10))

        rb2 = Radiobutton(actionSelectionFrame, text='Custom Prefix', variable=status, font=('Flux Regular', 10, 'bold'), value= 1)
        rb2.grid(row=0, column=1, ipady=5, ipadx=5, padx=5, pady=(10, 10))

        rb3 = Radiobutton(actionSelectionFrame, text='Custom File Name ', variable=status, font=('Flux Regular', 10, 'bold'), value= 1)
        rb3.grid(row=0, column=2, ipady=5, ipadx=5, padx=5, pady=(10, 10))

        # Second Row end


        return R_Frame

此代码从另一个文件中取胜,并使用该窗口显示当前的[R_Frame]帧。我想配置R_FrameContent Frame 的第二列。所以基本上我希望第二列 选择操作列展开。

如果有人可以向我解释有关 grid_rowconfigure 和 grid_columnconfigure 的信息,那将非常有帮助。

非常感谢您的帮助。

在此处输入图像描述

标签: tkinter

解决方案


推荐阅读