I'm building a Python tkinter popup as a subclass of simpledialog.Dialog with nothing but specialized buttons. The body method only gives the dialog label and returns None.
The buttonbox method defines the buttons and the commands are fine. When I place the buttons with pack, everything works fine. But if I try to use grid instead, as I normally do in the body method of other dialogs, the dialog doesn't show at all though the app continues to run.
Is there a call I'm missing to make it appear?
The buttonbox methods has nothing except the button creations and placements. No other calls.
For several reasons, I prefer to use grid, not pack.
The basic structure is body, apply, and buttonbox plus the command methods. The same problem occurs if I grid a Label into the body.
Note: other questions are similar, but I think this is a buttonbox issue specifically.
from tkinter import simpledialog, Button, Tk, LEFT
class FooDialog(simpledialog.Dialog):
def __init__(self, root):
super().__init__(root)
__val = "mumble"
@classmethod
def get(cls):
return FooDialog.__val
def getResult(self):
return FooDialog.__val
def handle(self, which):
if not which:
FooDialog.__val = "jumble"
self.destroy()
def buttonbox(self):
noButton = Button(self, text="Foo", width=10, command= lambda t=False: self.handle(t))
noButton.pack(side=LEFT, padx=5, pady=5)
def body(self, master):
self.title('Foo')
return None
def apply(self):
FooDialog.__val = self.getResult()
def foo():
root = Tk()
root.withdraw()
FooDialog(root)
root.destroy()
return FooDialog.get()
if __name__ == '__main__':
print( foo())
If I replace the grid call with:
noButton.grid(row=0, column=0)
nothing will appear