[Tkinter-discuss] How to launch a dialog when app is started?
Russell Blau
russblau at hotmail.com
Thu Mar 2 22:14:54 CET 2006
I am trying to write a Tkinter application that will automatically display a
particular dialog box on top of the application when it is initialized.
(Like a word processor opening a "File Open" dialog as the first thing that
happens when you enter the application.) How do I do this? I have a method
that invokes the dialog box, but I cannot call it until after my app's
mainloop has started; but once the mainloop has started, I can't call it
from the program, either!
I'm sure I'm overlooking something obvious here.
Example (skeleton) code:
from Tkinter import *
class NewPageDialog(tkSimpleDialog.Dialog):
def body(self, master, title="Select Target"):
Label(master, text="Target page:").grid(row=0)
self.targetpage = Entry(master)
self.targetpage.grid(row=0, column=1)
return self.targetpage
def validate(self):
return True
def apply(self):
pass
class GuiApplication(Frame):
def __init__(self, master):
Frame.__init__(self, master)
def newpage(self):
n = NewPageDialog(self)
self.targetpage = n.targetpage.get()
if __name__ == "__main__":
app = GuiApplication(Tk())
# do something here to cause GuiApplication to invoke newpage() method
when it starts
app.mainloop()
More information about the Tkinter-discuss
mailing list