By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,199 Members | 1,125 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,199 IT Pros & Developers. It's quick & easy.

TK question

P: n/a
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

Oct 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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

On Thursday 20 October 2005 19:16, MBW wrote:
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/
Oct 21 '05 #2

P: n/a
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

On Thursday 20 October 2005 19:16, MBW wrote:
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/
Oct 21 '05 #3

P: n/a
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

Oct 21 '05 #4

P: n/a
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-----

Oct 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.