Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'insert': 0.05; 'context': 0.07; 'responding': 0.07; 'tkinter': 0.07; '%s"': 0.09; 'python': 0.11; 'def': 0.12; 'project,': 0.12; 'assume': 0.14; 'elementos': 0.16; 'luck,': 0.16; 'luckily,': 0.16; 'namespace.': 0.16; 'numero': 0.16; 'numpy': 0.16; 'quantum': 0.16; 'renamed': 0.16; 'responses.': 0.16; 'subject:Tkinter': 0.16; 'tk()': 0.16; 'to:name:python list': 0.16; 'wrote:': 0.18; 'do.': 0.18; 'variable': 0.18; 'module': 0.19; 'trying': 0.19; 'input': 0.22; 'import': 0.22; 'entries': 0.24; 'finally,': 0.24; 'ph.d.': 0.24; '\xa0so': 0.24; 'task': 0.26; 'this:': 0.26; 'pass': 0.26; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'to:2**1': 0.27; 'function': 0.29; 'leave': 0.29; 'am,': 0.29; 'label': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'gives': 0.31; 'skip:c 30': 0.32; 'skip:m 30': 0.32; 'guess': 0.33; 'lab': 0.33; 'skip:t 40': 0.33; 'candidate': 0.34; 'received:google.com': 0.35; 'add': 0.35; 'version': 0.36; '(e.g.,': 0.36; 'replies': 0.36; 'thanks': 0.36; 'should': 0.36; 'list': 0.37; 'skip:& 10': 0.38; '8bit%:4': 0.38; 'bringing': 0.38; 'jason': 0.38; 'window': 0.38; 'to:addr:python-list': 0.38; 'does': 0.39; '\xa0\xa0\xa0': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'university': 0.39; 'called': 0.40; 'tell': 0.60; 'skip:t 30': 0.61; 'skip:n 10': 0.64; 'to:addr:gmail.com': 0.65; 'media': 0.66; 'click': 0.77; 'florida': 0.78; 'responses': 0.93; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=QUFzr0QN2wkyMiJXWkKrg/R40a3K/kfYxXYus6CWcfw=; b=m5qbkDosPWjb9AFvfEtszTr7GXleulwwgfY2pelACqObZTa+Fzl3C75HT199ro1CXb H9WYDdPoB15O24xD5jg0hyluW1aXnWYZ0IjxtqkqRBGkZYdkkZujZpRKOylf4R5YawLY PqQCB6LfDN8k5oiuetXuTWGshoUMDGFDDTE1jdi6xT4NbqlsL1Vo5euJwFFK4ZxJA8ci TVfSYU3b9c/1wXTO+KZbpKBy3nQSMOTBqlObL89/5ckp598Fdpx8svvK128f3Yb7El1e 7O42zWq2sYPVdKWlyt7xppnfr+CEUDazh+2SmE97qFvjf5D371vs0OuMFr8gqWMAbdSc G6eg== MIME-Version: 1.0 X-Received: by 10.50.190.233 with SMTP id gt9mr5460757igc.80.1364919099272; Tue, 02 Apr 2013 09:11:39 -0700 (PDT) In-Reply-To: References: Date: Tue, 2 Apr 2013 12:11:39 -0400 Subject: Re: Tkinter From: Jason Swails To: Renato Barbosa Pim Pereira , python list Content-Type: multipart/alternative; boundary=14dae93411770f352c04d962fefa X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 189 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1364919108 news.xs4all.nl 6976 [2001:888:2000:d::a6]:53851 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:42587 --14dae93411770f352c04d962fefa Content-Type: text/plain; charset=ISO-8859-1 Please keep response replies to the Python list (e.g., use 'reply all' or just send the email to python-list). Also, you should tell people what Python version you are using. I assume you are using Python 2 since Tkinter was renamed to tkinter in Python 3. Finally, do not top-post. Type your responses inside the body of the email you are responding to. That gives people context for your responses. On Tue, Apr 2, 2013 at 11:48 AM, Renato Barbosa Pim Pereira < renato.barbosa.pim.pereira@gmail.com> wrote: > Sorry for my inconsistence: > > I need a textbox to get one number and pass for variable called numero > with one click of button. Thanks . > > I have this: > > import numpy as np > import matplotlib.pyplot as plt > from Tkinter import * > import tkMessageBox > > prefixo = "vetor" > numero = 10 > numeroVetores = 0 > > def makeWidgets(numero): > global entries > window = Tk() > window.title('Vetores') > form = Frame(window) > form.pack() > entries = {} > for ix in range(numero): > label = "%s %s" % (prefixo , ix + 1) > lab = Label(form, text=label) > ent = Entry(form) > lab.grid(row=ix, column=0) > ent.grid(row=ix, column=1) > entries[label] = ent > > > > > > Button(window, text="Calcular", command=calcular).pack(side=LEFT) > Button(window, text="Media", command=media).pack(side=LEFT) > > > > return window > > > > def pegavalores(): > valores = [] > for chave, entrada in sorted(entries.items()): > valores.append(entrada.get()) > > return valores > > > def calcular(): > calcular = pegavalores() > plt.plot(calcular) > plt.show() > > def media(): > media = pegavalores() > elementos = len(media) > media = np.asarray(media, dtype=np.float64) > valormedio = np.sum(media)/elementos > tkMessageBox.showinfo("Media", valormedio) > > > window = makeWidgets(numero) > window.mainloop() > I'm not sure exactly what you are trying to do. My guess is that you want to get "numero" from user input. Luckily, the tkSimpleDialog module contains a handy function that does just this: askinteger. So add a call: numero = tkSimpleDialog.askinteger('Window Title', 'Please insert the number of input values you want') window = makeWidgets(numero) window.mainloop() I leave to you the task of bringing tkSimpleDialog into your namespace. Good luck, Jason -- Jason M. Swails Quantum Theory Project, University of Florida Ph.D. Candidate 352-392-4032 --14dae93411770f352c04d962fefa Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Pl= ease keep response replies to the Python list (e.g., use 'reply all'= ; or just send the email to python-list).
<= br>
Also, you should tell people what Python version you are using. I a= ssume you are using Python 2 since Tkinter was renamed to tkinter in Python= 3.

Finally, do not top-post. = =A0Type your responses inside the body of the email you are responding to. = =A0That gives people context for your responses.

On Tue, Apr 2, 2013 at 11:48 AM, Renato Barbosa Pim Perei= ra <renato.barbosa.pim.pereira@gmail.com>= wrote:
Sorry for my inconsist= ence:

I need a textbox to get one number and pass for var= iable called numero with one click of button. Thanks .

I have this:

import numpy as np
import matplotlib.pyplot as plt
from Tkinter import *
import tkMessag= eBox

prefixo =3D "vetor"
numero =3D 10
numeroVetores= =3D 0

def makeWidgets(numero):
=A0=A0=A0 global entries
=A0= =A0=A0 window =3D Tk()
=A0=A0=A0 window.title('Vetores')
=A0=A0=A0 form =3D Frame(windo= w)
=A0=A0=A0 form.pack()
=A0=A0=A0 entries =3D {}
=A0=A0=A0 for ix= in range(numero):
=A0=A0=A0=A0=A0=A0=A0 label =3D "%s %s" % (= prefixo , ix + 1)
=A0=A0=A0=A0=A0=A0=A0 lab =3D Label(form, text=3Dlabel= )
=A0=A0=A0=A0=A0=A0=A0 ent =3D Entry(form)
=A0=A0=A0=A0=A0=A0=A0 lab.grid= (row=3Dix, column=3D0)
=A0=A0=A0=A0=A0=A0=A0 ent.grid(row=3Dix, column= =3D1)
=A0=A0=A0=A0=A0=A0=A0 entries[label] =3D ent
=A0=A0=A0=A0=A0=A0= =A0
=A0=A0=A0=A0=A0=A0=A0
=A0=A0=A0=A0=A0=A0=A0
=A0=A0=A0
= =A0=A0=A0=A0=A0=A0=A0
=A0=A0=A0 Button(window, text=3D"Calcular&qu= ot;,=A0 command=3Dcalcular).pack(side=3DLEFT)
=A0=A0=A0 Button(window, text=3D"Media",=A0 command=3Dmedia).pack= (side=3DLEFT)

=A0=A0=A0

=A0=A0=A0 return window


<= br>def pegavalores():
=A0=A0=A0 valores =3D []
=A0=A0=A0 for chave, e= ntrada in sorted(entries.items()):
=A0=A0=A0=A0=A0=A0=A0 valores.append(entrada.get())

=A0=A0=A0 return= valores


def calcular():
=A0=A0=A0 calcular =3D pegavalores()=
=A0=A0=A0 plt.plot(calcular)
=A0=A0=A0 plt.show()

def media()= :
=A0=A0=A0 media =3D pegavalores()
=A0=A0=A0 elementos =3D len(media= )
=A0=A0=A0 media =3D np.asarray(media, dtype=3Dnp.float64)
=A0=A0=A0 valo= rmedio =3D np.sum(media)/elementos
=A0=A0=A0 tkMessageBox.showinfo("= ;Media", valormedio)


window =3D makeWidgets(numero)
wind= ow.mainloop()

I'm not sure exactly what you are trying to do. =A0My guess is= that you want to get "numero" from user input. =A0Luckily, the t= kSimpleDialog module contains a handy function that does just this: askinte= ger. =A0So add a call:

numero =3D tkSimpleDialog.as= kinteger('Window Title', 'Please insert the number of input val= ues you want')
window =3D makeWidg= ets(numero)
wi= ndow.mainloop()

I leave to you the = task of bringing tkSimpleDialog into your namespace.

Good luck,
Jas= on
--
Jason M. Swails
Quantum Theory Project,
University of Florida=
Ph.D. Candidate
352-392-4032
--14dae93411770f352c04d962fefa--