python, tkinter: Using grid layout, my frame refuses to display its contents

Trying to use grid geometry instead of pack(), but using a frame without use of pack() has me lost. All I Want is a frame around it so that I can have a border and label around certain sections. I suspect the width and height parameters are the problem here.

from tkinter import *

class App:

    def __init__(self,master):

        frame = Frame(master,height=20,width=25)

        #Multiple buttons, over n rows and columns, these are just here to demonstrate my syntax
        self.action = Button(frame,text="action",command=self.doAction)
        self.action.grid(row=n,column=n)

    def doAction(self):
        print('Action')

root = Tk()

app = App(root)

root.mainloop()

Upvotes: 0

Views: 1634

Answers (2)

Bryan Oakley
Bryan Oakley

Reputation: 385810

The frame you create in the first statement of the constructor is never placed anywhere in its parent window. Since the other widgets are children of this widget, they won't be displayed either.

Upvotes: 1

xor
xor

Reputation: 2698

may be you are trying to do something like this.

class App:
    def __init__(self,master):

        frame = Frame(master,height=20,width=25)
        frame.grid()
        #Multiple buttons, over n rows and columns, these are just here to demonstrate my syntax
        for i in range(n):
            frame.columnconfigure(i,pad=3)
        for i in range(n):
            frame.rowconfigure(i,pad=3)

        for i in range(0,n):
            for j in range(0,n):
                self.action = Button(frame,text="action",command=self.doAction)
                self.action.grid(row=i,column=j)

    def doAction(self):
        print('Action')

Upvotes: 0

Related Questions