python Tkinter: grid + pack == hang

Status
Not open for further replies.

DavlinLotze

Ars Scholae Palatinae
830
TIL this hangs:
Code:
from Tkinter import *
root = Tk()
app = Frame()
app.pack()
infolabel = Label(app, text="Howdy, world.")
infolabel.grid(row=0, column=0)
quitbutton = Button(app, text="QUIT", command=app.quit)
quitbutton.pack()
app.mainloop()
root.destroy()

The fun part about this in debugging a more complex program is that you probably won't even get a window displayed if you just run it, and no error messages, however if you run it line by line in the interactive interpreter, you do get a window that does work, except for taking more CPU power.

The quitbutton.pack() is the line that turns the CPU into a heater, but that's not always the point at which Python becomes unresponsive. If you run it line by line, it works, but if you put all but the last two lines into a file (e.g. gridlock.py) and then try running from gridlock import * from the interactive prompt, then it will hang as soon as you do, and you never get a window.

I'm new to Tkinter, so my questions are:
1) Is this just a basic rule that pack and grid don't mix, or do they sometimes?
2) Could they not have just given me an error message instead?
 
Status
Not open for further replies.