TK question

M

MBW

I have a class that is a windows in a GUI

the following is the code:

class optWin:

def __init__(self):
return None

def __call__(self):
self.root = tk()
self.root.title("My title")
self.root.mainloop()
return None

1)Why doesn't this work when I go to call optWin
2)What is a better way to do this

Thanks in advance
 
J

James Stroud

optWin() will create a callable object which is an instance of the class
optWin. Calling this callable object will call the __call__() method with the
behavior you anticipate. You also need to import Tk from Tkinter and call Tk
"Tk" and not "tk".

Meditate on the following :


from Tkinter import *

class optWin:

def __init__(self):
return None

def __call__(self):
self.root = Tk()
self.root.title("My title")
self.root.mainloop()
return None

ow = optWin()
ow()


James

class optWin:

    def __init__(self):
        return None

    def __call__(self):
        self.root = tk()
        self.root.title("My title")
        self.root.mainloop()
        return None

--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/
 
J

James Stroud

Forgot to answer the "better" part:


class optFrame(Frame):

def __init__(self, *args, **kwargs):
Frame.__init__(self, *args, **kwargs)
self.pack()
self.make_widgets()
def make_widgets(self):
"""
Put widgets here.
"""
pass


def main():

tk = Tk()
optWin = optFrame(tk)
tk.mainloop()


if __name__ == "__main__":

main()


James

I have a class that is a windows in a GUI

the following is the code:

class optWin:

def __init__(self):
return None

def __call__(self):
self.root = tk()
self.root.title("My title")
self.root.mainloop()
return None

1)Why doesn't this work when I go to call optWin
2)What is a better way to do this

Thanks in advance

--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/
 
M

MBW

thank you very much,
I have one more question that is tk related, I've use tkfileopendialog
or whatever that name is to select files is there also a dialog for
creating files, well not really creating them but allowing the same
look and feel as many porgrams give for saving files? is there also a
way/dialog whereby a user can specify a directory (if the application
wanted to save multiple files into a 'project' folder)

Thanks agian for the quick and accurate response to my first question,
a small follow-up.. is it considered bad style to include main
methods(and if __name__== "__main__") in all user defined classes, I
realize it's usefulness when testing individual classes.

thanks very much
Matt

Totally aside PyDEV is so much better then trustudio it runs smooth and
isn't such a resource hog.. not to mention free
 
J

jepler

In the FileDialog module there are both LoadFileDialog and SaveFileDialog. Is
the latter what you want?

Jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFDWNcfJd01MZaTXX0RAurxAKCDwMdPKeQEWACwtSlGfm/pSLZCQwCeNiBa
9Ovk6cM0i2pBJfR9vqUY9k8=
=xO23
-----END PGP SIGNATURE-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,269
Messages
2,571,348
Members
48,026
Latest member
ArnulfoCat

Latest Threads

Top