Greetings pythonistas,

I have been exploring the use of Tkinter trying to write a fairly simple 
program which will accept data from a GUI with 3 Entry fields that is commanded 
by a Button. Once the button is pressed the values in the fields should result 
in a calculation - the values should all be numeric (I'll work on catching 
errors later) but I can not figure out how to pass those values to the callback 
function for the button. Here is my code so far:

from Tkinter import *

class App:

    def __init__( self, master ):

        frame = Frame( master )
        
        frame.grid()
        
        entry1 = Entry( frame, bg = "white", width = 3 ).grid(row = 0, column = 
0 )
        Label( frame, text = "X^2 +" ).grid( row = 0, column = 1 )
        entry2 = Entry( frame, bg = "white", width = 3 ).grid(row = 0, column = 
2 )
        Label( frame, text = "X +" ).grid( row = 0, column = 3 )
        entry3 = Entry( frame, bg = "white", width = 3 ).grid(row = 0, column = 
4 )
        Label( frame, text = "= 0" ).grid( row = 0, column = 5 )
        
        calcbutton = Button( text = "How many Real roots?", command = 
self.calculate )
        calcbutton.grid( row = 1, column = 0 )

    def calculate( self ):
        print 1
        
root = Tk()

root.geometry( '250x100+450+70' )

app = App( root )

root.mainloop()

Now the above code runs, but I need to figure out how to get the contents of 
the fields entry1, entry2 and entry3 to the calculate method. Or maybe I am 
going about this all wrong and there is a better way to do it. Any help would 
be appreciated.

Brett
On Jul 13, 2013, at 9:54 AM, [email protected] wrote:

> Send Tutor mailing list submissions to
>       [email protected]
> 
> To subscribe or unsubscribe via the World Wide Web, visit
>       http://mail.python.org/mailman/listinfo/tutor
> or, via email, send a message with subject or body 'help' to
>       [email protected]
> 
> You can reach the person managing the list at
>       [email protected]
> 
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Tutor digest..."
> 
> 
> Today's Topics:
> 
>   1. Re: A slight bug in IDLE (Steven D'Aprano)
>   2. Re: Matrix Multiplication and its Inverse (Steven D'Aprano)
>   3. Re: A slight bug in IDLE (eryksun)
>   4. Re: A slight bug in IDLE (eryksun)
>   5. IOError when importing nose (Albert-Jan Roskam)
>   6. Re: IOError when importing nose (Walter Prins)
> 
> 
> ----------------------------------------------------------------------
> 
> Message: 1
> Date: Sat, 13 Jul 2013 20:11:48 +1000
> From: Steven D'Aprano <[email protected]>
> To: [email protected]
> Subject: Re: [Tutor] A slight bug in IDLE
> Message-ID: <[email protected]>
> Content-Type: text/plain; charset=UTF-8; format=flowed
> 
> On 13/07/13 18:39, Jim Mooney wrote:
>> On 13 July 2013 00:54, eryksun <[email protected]> wrote:
>> 
>> 
>>> A __future__ import modifies compilation of the current module.
>>> 
>> 
>> Hmm, so if I import a module that uses truncated division, that's what I
>> get, even though I imported __future__ division. OTOH, a non-future import
>> will be used by a module imported after it. That's a gotcha to avoid ;')
> 
> 
> No, actually, it's the opposite of a gotcha. If a module expects to use 
> truncated division, and *fails* to "from __future__ import division", that's 
> what it needs to get. If your import would change what the other module sees, 
> then you could change the behaviour of the other module (and probably break 
> it) just by importing something from __future__.
> 
> By the way, you can import __future__, but when you do, it is just an 
> ordinary module with no superpowers. Only the "from __future__ import ..." in 
> the first or second line of code has superpowers. Try this:
> 
> import __future__
> dir(__future__)
> 
> 
> -- 
> Steven
> 
> 
> ------------------------------
> 
> Message: 2
> Date: Sat, 13 Jul 2013 21:54:46 +1000
> From: Steven D'Aprano <[email protected]>
> To: [email protected]
> Subject: Re: [Tutor] Matrix Multiplication and its Inverse
> Message-ID: <[email protected]>
> Content-Type: text/plain; charset=UTF-8; format=flowed
> 
> On 13/07/13 05:05, Jack Little wrote:
>> Is there a way in python to do matrix multiplication and its inverse? No 
>> external modules is preferred, but it is ok.
> 
> 
> If you have numpy, you should use that.
> 
> If you want a pure Python version, here's a quick and dirty matrix multiplier 
> that works only for 2x2 matrices.
> 
> 
> def is_matrix(obj):
>     if len(obj) == 2:
>         return len(obj[0]) == 2 and len(obj[1]) == 2
>     return False
> 
> 
> def matrix_mult(A, B):
>     """Return matrix A x B."""
>     if not (is_matrix(A) and is_matrix(B)):
>         raise ValueError('not matrices')
>     [a, b], [c, d] = A
>     [w, x], [y, z] = B
>     return [[a*w + b*y, a*x + b*z],
>             [c*w + d*y, c*x + d*z]]
> 
> 
> I leave the inverse as an exercise :-)
> 
> 
> 
> -- 
> Steven
> 
> 
> ------------------------------
> 
> Message: 3
> Date: Sat, 13 Jul 2013 08:43:45 -0400
> From: eryksun <[email protected]>
> To: Jim Mooney <[email protected]>
> Cc: [email protected]
> Subject: Re: [Tutor] A slight bug in IDLE
> Message-ID:
>       <CACL+1av-f=sle6ysvvg9js-8w7bewvqhdxwcklgh+spxx30...@mail.gmail.com>
> Content-Type: text/plain; charset=UTF-8
> 
> On Sat, Jul 13, 2013 at 4:39 AM, Jim Mooney <[email protected]> wrote:
>> On 13 July 2013 00:54, eryksun <[email protected]> wrote:
>> 
>>> 
>>> A __future__ import modifies compilation of the current module.
>> 
>> 
>> Hmm, so if I import a module that uses truncated division, that's what I
>> get, even though I imported __future__ division. OTOH, a non-future import
>> will be used by a module imported after it. That's a gotcha to avoid ;')
> 
> You wouldn't want to force true division on a module written for
> classic division -- or any other __future__ feature for that matter.
> 
> FWIW, here's a simple overview of what's happening with IDLE. It's
> using a subclass of code.InteractiveInterpreter:
> 
>    import code
> 
>    interp = code.InteractiveInterpreter()
>    interp.runsource('from __future__ import division')
> 
> This saves the flags corresponding to __future__ imports in a
> codeop.Compiler instance:
> 
>>>> ok = interp.runsource('print 5 / 3')
>    1.66666666667
>>>> interp.compile.compiler.flags & CO_FUTURE_DIVISION
>    8192
> 
> However, "Run Module" just uses a vanilla compile() call. See the
> checksyntax() and run_module_event() methods in ScriptBinding.py [1]:
> 
> run_module_event could update the flags before returning, like so:
> 
>    from codeop import _features
>    compiler = interp.compile.compiler
>    for feature in _features:
>        if code.co_flags & feature.compiler_flag:
>            compiler.flags |= feature.compiler_flag
> 
> This would approximate running a script with -i (inspect) from the
> command line, which drops into the interactive loop using the current
> compiler flags (cf) [2].
> 
> [1] http://hg.python.org/cpython/file/2.7/Lib/idlelib/ScriptBinding.py
> [2] http://hg.python.org/cpython/file/ab05e7dd2788/Modules/main.c#l648
> 
> 
> ------------------------------
> 
> Message: 4
> Date: Sat, 13 Jul 2013 08:47:44 -0400
> From: eryksun <[email protected]>
> To: "Steven D'Aprano" <[email protected]>
> Cc: [email protected]
> Subject: Re: [Tutor] A slight bug in IDLE
> Message-ID:
>       <cacl+1at+npuytfmx-wqscfb0f8ilvjqczx1ftrnny_vd5cr...@mail.gmail.com>
> Content-Type: text/plain; charset=UTF-8
> 
> On Sat, Jul 13, 2013 at 6:11 AM, Steven D'Aprano <[email protected]> wrote:
>> By the way, you can import __future__, but when you do, it is just an
>> ordinary module with no superpowers. Only the "from __future__ import ..."
>> in the first or second line of code has superpowers. Try this:
>> 
>> import __future__
>> dir(__future__)
> 
> I thought this was clear in my description:
> 
>>>> __future__.CO_FUTURE_DIVISION  # flag
>    8192
>>>> __future__.division
>    _Feature((2, 2, 0, 'alpha', 2), (3, 0, 0, 'alpha', 0), 8192)
> 
> Note to self: next time show "import __future__".
> 
> 
> ------------------------------
> 
> Message: 5
> Date: Sat, 13 Jul 2013 07:14:16 -0700 (PDT)
> From: Albert-Jan Roskam <[email protected]>
> To: Python Mailing List <[email protected]>
> Subject: [Tutor] IOError when importing nose
> Message-ID:
>       <[email protected]>
> Content-Type: text/plain; charset=iso-8859-1
> 
> Hi,
> 
> I am using nose on my laptop (installed it using sudo pip install nose), but 
> I get the following error, unless I run python as sudo. Why is this 
> happening, and what can I do to solve this problem? Maybe use chown? I 
> uninstalled and reinstalled the package already, but it did not solve the 
> problem.
> 
> 
> Python 2.7.3 (default, Sep 26 2012, 21:53:58) 
> [GCC 4.7.2] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import nose
> Traceback (most recent call last):
> ? File "<stdin>", line 1, in <module>
> ? File "/usr/local/lib/python2.7/dist-packages/nose/__init__.py", line 1, in 
> <module>
> ??? from nose.core import collector, main, run, run_exit, runmodule
> ? File "/usr/local/lib/python2.7/dist-packages/nose/core.py", line 11, in 
> <module>
> ??? from nose.config import Config, all_config_files
> ? File "/usr/local/lib/python2.7/dist-packages/nose/config.py", line 9, in 
> <module>
> ??? from nose.plugins.manager import NoPlugins
> ? File "/usr/local/lib/python2.7/dist-packages/nose/plugins/__init__.py", 
> line 185, in <module>
> ??? from nose.plugins.manager import *
> ? File "/usr/local/lib/python2.7/dist-packages/nose/plugins/manager.py", line 
> 418, in <module>
> ??? import pkg_resources
> ? File 
> "/usr/local/lib/python2.7/dist-packages/distribute-0.6.34-py2.7.egg/pkg_resources.py",
>  line 2823, in <module>
> ??? add_activation_listener(lambda dist: dist.activate())
> ? File 
> "/usr/local/lib/python2.7/dist-packages/distribute-0.6.34-py2.7.egg/pkg_resources.py",
>  line 710, in subscribe
> ??? callback(dist)
> ? File 
> "/usr/local/lib/python2.7/dist-packages/distribute-0.6.34-py2.7.egg/pkg_resources.py",
>  line 2823, in <lambda>
> ??? add_activation_listener(lambda dist: dist.activate())
> ? File 
> "/usr/local/lib/python2.7/dist-packages/distribute-0.6.34-py2.7.egg/pkg_resources.py",
>  line 2255, in activate
> ??? self.insert_on(path)
> ? File 
> "/usr/local/lib/python2.7/dist-packages/distribute-0.6.34-py2.7.egg/pkg_resources.py",
>  line 2362, in insert_on
> ??? self.check_version_conflict()
> ? File 
> "/usr/local/lib/python2.7/dist-packages/distribute-0.6.34-py2.7.egg/pkg_resources.py",
>  line 2401, in check_version_conflict
> ??? for modname in self._get_metadata('top_level.txt'):
> ? File 
> "/usr/local/lib/python2.7/dist-packages/distribute-0.6.34-py2.7.egg/pkg_resources.py",
>  line 2249, in _get_metadata
> ??? for line in self.get_metadata_lines(name):
> ? File 
> "/usr/local/lib/python2.7/dist-packages/distribute-0.6.34-py2.7.egg/pkg_resources.py",
>  line 1219, in get_metadata_lines
> ??? return yield_lines(self.get_metadata(name))
> ? File 
> "/usr/local/lib/python2.7/dist-packages/distribute-0.6.34-py2.7.egg/pkg_resources.py",
>  line 1211, in get_metadata
> ??? return self._get(self._fn(self.egg_info,name))
> ? File 
> "/usr/local/lib/python2.7/dist-packages/distribute-0.6.34-py2.7.egg/pkg_resources.py",
>  line 1326, in _get
> ??? stream = open(path, 'rb')
> IOError: [Errno 13] Permission denied: 
> '/usr/local/lib/python2.7/dist-packages/pypi_classifiers-0.1-py2.7.egg/EGG-INFO/top_level.txt'
>>>> quit()
> antonia@antonia-HP-2133 
> /usr/local/lib/python2.7/dist-packages/pypi_classifiers-0.1-py2.7.egg/EGG-INFO
>  $ ls -l
> total 24
> -rw------- 1 root staff??? 1 Jan 26 14:36 dependency_links.txt
> -rw------- 1 root staff 1311 Jan 26 14:36 PKG-INFO
> drwxr-sr-x 2 root staff 4096 Jan 26 14:36 scripts
> -rw------- 1 root staff? 269 Jan 26 14:36 SOURCES.txt
> -rw------- 1 root staff?? 16 Jan 26 14:36 top_level.txt
> -rw-r--r-- 1 root staff??? 1 Jan 26 14:36 zip-safe
> 
> ?0.1-py2.7.egg/EGG-INFO $ 
> antonia@antonia-HP-2133 
> /usr/local/lib/python2.7/dist-packages/pypi_classifiers-0.1-py2.7.egg/EGG-INFO
>  $ cd scripts
> antonia@antonia-HP-2133 
> /usr/local/lib/python2.7/dist-packages/pypi_classifiers-0.1-py2.7.egg/EGG-INFO/scripts
>  $ ls -l
> total 4
> -rwxr-xr-x 1 root staff 1386 Jan 26 14:36 pypi-classifiers
> 
> Thank you in advance!
> 
> 
> Regards,
> Albert-Jan
> 
> 
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> All right, but apart from the sanitation, the medicine, education, wine, 
> public order, irrigation, roads, a 
> fresh water system, and public health, what have the Romans ever done for us?
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~?
> 
> 
> ------------------------------
> 
> Message: 6
> Date: Sat, 13 Jul 2013 15:54:25 +0100
> From: Walter Prins <[email protected]>
> Cc: Python Mailing List <[email protected]>
> Subject: Re: [Tutor] IOError when importing nose
> Message-ID:
>       <CANLXbfC=0mr=2hvnsoewquveelbyjax1-sowa6hqcr_gday...@mail.gmail.com>
> Content-Type: text/plain; charset="iso-8859-1"
> 
> Hi,
> 
> 
> On 13 July 2013 15:14, Albert-Jan Roskam <[email protected]> wrote:
> 
>> IOError: [Errno 13] Permission denied:
>> '/usr/local/lib/python2.7/dist-packages/pypi_classifiers-0.1-py2.7.egg/EGG-INFO/top_level.txt'
>>>>> quit()
>> antonia@antonia-HP-2133/usr/local/lib/python2.7/dist-packages/pypi_classifiers-0.1-py2.7.egg/EGG-INFO
>> $ ls -l
>> total 24
>> -rw------- 1 root staff    1 Jan 26 14:36 dependency_links.txt
>> -rw------- 1 root staff 1311 Jan 26 14:36 PKG-INFO
>> drwxr-sr-x 2 root staff 4096 Jan 26 14:36 scripts
>> -rw------- 1 root staff  269 Jan 26 14:36 SOURCES.txt
>> -rw------- 1 root staff   16 Jan 26 14:36 top_level.txt
>> -rw-r--r-- 1 root staff    1 Jan 26 14:36 zip-safe
>> 
>> 
> It appears to me this is not directly a problem with your nose
> installation.  As you can see it's apparently some other package
> (pypi_classifiers) which has previously been installed and has incorrect
> file permissions on some files that's causing trouble.
> 
> (As an aside re your nose installation, note that on Linux it's slightly
> preferable to use the package manager if available to install even Python
> packages, instead of pip if possible, e.g on Debian and variants (Ubuntu,
> Mint etc) you'd use: sudo apt-get install python-nose)
> 
> That said, if you want to try and blanket fix your current permissions to
> give group and world (other) readability on all the files in dist-packages
> (probably a reasonable fix to do) you can do:
> 
> sudo chmod -R go+r /usr/loca/lib/python2.7/dist-packages
> 
> Some clarification of options:
> -R = recursive
> go = apply to "group" and "other"
> + = add permissions
> r = read permission
> 
> You can also try uninstalling via pip again (sudo pip uninstall nose) and
> then try installing via the package manager again to see if this helps (but
> as above, I don't think it will, the problem appears to me not to be
> directly related to your nose installation.)
> 
> 
> Walter
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: 
> <http://mail.python.org/pipermail/tutor/attachments/20130713/18b67734/attachment.html>
> 
> ------------------------------
> 
> Subject: Digest Footer
> 
> _______________________________________________
> Tutor maillist  -  [email protected]
> http://mail.python.org/mailman/listinfo/tutor
> 
> 
> ------------------------------
> 
> End of Tutor Digest, Vol 113, Issue 46
> **************************************

_______________________________________________
Tutor maillist  -  [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to