[Tutor] TKinter - display dialog w/o using mainloop()

Don Arnold Don Arnold" <darnold02@sprynet.com
Fri Mar 7 22:55:02 2003


----- Original Message -----
From: "Bob Gailer" <ramrom@earthling.net>
To: <tutor@python.org>
Sent: Friday, March 07, 2003 12:25 PM
Subject: [Tutor] TKinter - display dialog w/o using mainloop()


> class Dialog(Frame):
>    def __init__(self):
>      Frame.__init__(self, None)
>      self.pack()
>      self.Label['text'] = 'initial text'
>      self.Label.pack({"side": "top"})
> d = Dialog()
>
> How do I get the dialog box to be visible w/o using mainloop(). I want to
> show the dialog and then do other things in my program, which might result
> in reassigning d.Label['text'] = 'new text'

Well, I admit I know even less about Tkinter than most other aspects of
Python,
but I _think_ you just need to inherit Dialog from Toplevel instead of
Frame:

from Tkinter import *

class Dialog(Toplevel):
   def __init__(self,parent):
     Toplevel.__init__(self, parent)
     l = Label(self,text='initial text')
     l.pack(side=TOP)
     b = Button(self,text='close me',command=self.destroy)
     b.pack()

class App(Frame):
    def __init__(self,parent):
        Frame.__init__(self,parent)
        self.pack()
        w = Label(self, text="Hello, world!")
        w.pack()
        b = Button(self,text='open a dialog',command=self.makeDialog)
        b.pack()

    def makeDialog(self):
        Dialog(self)

root = Tk()

theApp = App(root)
theApp.mainloop()

HTH,

Don