[python-win32] Tkinter newbie

Andreas Holtz A.Holtz at gmx.net
Mon Mar 2 22:48:58 CET 2015


Hi John,

seems you lack basic understanding of Python (and perhaps programming languages at all?).
I recommend you reading a book like
"Learning Python" from Mark Lutz or check some courses on
https://wiki.python.org/moin/BeginnersGuide/Programmers

Then you will learn the differences between attributes/variables (no "()") and functions (with () )
and methods (self.x() and x(self)).

Later you will ask Google "tkinter open file" and get as first result
http://tkinter.unpythonic.net/wiki/tkFileDialog

You will look at the example and understand that line 45 fullfill your needs:
tkFileDialog.askopenfile(mode='r', **self.file_opt)

But you'll ask yourself, where does **self.file_opt come from and you'll understand that line 20
is the interesting thing.

Eventually you'll understand, that
options = {}
options['defaultextension'] = '.txt'
options['filetypes'] = [('all files', '.*'), ('text files', '.txt')]
options['initialdir'] = 'C:\\'
options['initialfile'] = 'myfile.txt'
options['parent'] = root
options['title'] = 'This is a title'
selectedFile = tkFileDialog.askopenfile(mode='r', **options)

is the code you are looking for.

And perhaps you'll ask yourself, why you wanted to waste the precious time of others at the
beginning, when learning and exploring by yourself makes so much more fun.

Best Regards

Andreas

John Sampson schrieb am 02.03.2015 um 22:21:
> Hello -
> 
> I am trying to find out how to write code in Tkinter that opens a file-selection dialog so that I
> can open a file. It would be part of a program, not a whole program that does nothing else.
> 
> I have found many examples of Tkinter code, each one using a different approach, some using a
> geometry manager, some not, some using an object-oriented approach, some not, etc.
> What I am looking for are examples of code with explicit explanations of each *term* in the code,
> explaining what it is, what it does and why it has to be there, why in one place it has to be self.x
> but in another it has to be x(self), why it has to be followed by '()' in one place but not in
> another, how the variables are scoped and similar questions. At the moment all my guesses are wrong.
> 
> Are there any such examples?
> 
> Regards
> 
> John Sampson
> _______________________________________________
> python-win32 mailing list
> python-win32 at python.org
> https://mail.python.org/mailman/listinfo/python-win32
> 


More information about the python-win32 mailing list