3

I'm creating a simple Tkinter gui. However, something appears to be going haywire. Nothing is actually being 'pack'ed to the frame. Can anyone spot what I've done wrong? (Other than the issues caused by using 'from Tkinter import *', and the apparently un-useful 'do_nothing()' function.

#/usr/bin/python
from Tkinter import *

class gui:
    def __init__(self, parent):
        f = Frame(parent, width=300, height=500)
        f.pack(padx=30, pady=15)

        self.label = Label(f, text="Japanese Trainer")
        self.label.pack(side=TOP, padx=10, pady=12)

        self.txtlbl = Entry(f, justify=CENTER, text="", font=("Calibri", 15, "bold"), width=37)
        self.txtlbl.pack()
        self.txtlbl.grid(row=1, rowspan=2, sticky=E, pady=10, padx=40)

        self.button0 = Button(f, text="Kana Trainer", width=20, command=self.do_nothing)
        self.button0.pack()
        self.button0.grid(row=3, rowspan=2, sticky=W, pady=10, padx=40)

        self.button1 = Button(f, text="Vocab Trainer", width=20, command=self.do_nothing)
        self.button1.pack()
        self.button1.grid(row=3, rowspan=2, sticky=E, pady=10, padx=40)

    def do_nothing(self):
        self.txtlbl.delete(0, END)
        self.txtlbl.insert(END, "Command did nothing...")


root = Tk()
root.title('Eg.')
app = gui(root)

root.mainloop()

1 Answer 1

1

You are mixing grid and pack in the same master window. You can't do that. Each one will potentially resize the widgets they manage, and each will respond to resizes in the widgets they manage. So, pack will resize the widgets to fit, grid will recognize the change and try to resize widgets to fit, pack will recognize the change and try to resize widgets to fit, ... resulting in an endless loop.

You can use pack and grid together in the same program, but you cannot use them to manage the same container.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.