Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > simple Tkinter Question

Reply
Thread Tools

simple Tkinter Question

 
 
Maboroshi
Guest
Posts: n/a
 
      10-05-2004
Hi I was curious how I can pass arguments through a Tkinter Entry widget

say I have an Entry widget and a Button widget I enter text into the
entry and now I want the button to process the text is there a certain
command I have to use to assign the button to the entry or vise versa

anyhelp appreciated
 
Reply With Quote
 
 
 
 
Eric Brunel
Guest
Posts: n/a
 
      10-05-2004
Maboroshi wrote:
> Hi I was curious how I can pass arguments through a Tkinter Entry widget
>
> say I have an Entry widget and a Button widget I enter text into the
> entry and now I want the button to process the text is there a certain
> command I have to use to assign the button to the entry or vise versa
>
> anyhelp appreciated


Sorry, but you'll have to be a bit more specific than that. What is exactly your
problem? Getting and setting the text in the entry? Assigning an action to the
button? What do you mean exactly by "assign the button to the entry"?
--
- Eric Brunel <eric (underscore) brunel (at) despammed (dot) com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com

 
Reply With Quote
 
 
 
 
duikboot
Guest
Posts: n/a
 
      10-05-2004
Maboroshi wrote:
> Hi I was curious how I can pass arguments through a Tkinter Entry widget
>
> say I have an Entry widget and a Button widget I enter text into the
> entry and now I want the button to process the text is there a certain
> command I have to use to assign the button to the entry or vise versa
>
> anyhelp appreciated


Take a look at
http://www.pythonware.com/library/tk...tion/index.htm

example

from Tkinter import *

def pr_text():
text = entry.get()
print text

gui=Tk()
entry=Entry(gui)
entry.pack()
button=Button(gui, text="print", command=pr_text)
button.pack()

gui.mainloop()


--
http://www.baandersconsultancy.nl | http://www.nosonis.com
 
Reply With Quote
 
Eric Brunel
Guest
Posts: n/a
 
      10-05-2004
duikboot wrote:
> Maboroshi wrote:
>
>> Hi I was curious how I can pass arguments through a Tkinter Entry widget
>>
>> say I have an Entry widget and a Button widget I enter text into the
>> entry and now I want the button to process the text is there a certain
>> command I have to use to assign the button to the entry or vise versa
>>
>> anyhelp appreciated

>
>
> Take a look at
> http://www.pythonware.com/library/tk...tion/index.htm
>
> example
>
> from Tkinter import *
>
> def pr_text():
> text = entry.get()
> print text
>
> gui=Tk()
> entry=Entry(gui)
> entry.pack()
> button=Button(gui, text="print", command=pr_text)
> button.pack()
>
> gui.mainloop()


If *that* is the actual problem, I'd use a Tkinter StringVariable to do the job:

from Tkinter import *
root = Tk()
v = StringVar()
Entry(root, textvariable=v).pack()
def pr_text():
print v.get()
Button(root, text='Print', command=pr_text).pack()
root.mainloop()

Tkinter variables are a better choice because you often want to know what *was*
in your entry after it has been destroyed from the display. In such a case,
entry.get() will raise a TclError, because the entry no more exists. If you use
a variable, it will still be there after the entry was destroyed, so you can
still read its value.

HTH
--
- Eric Brunel <eric (underscore) brunel (at) despammed (dot) com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com

 
Reply With Quote
 
duikboot
Guest
Posts: n/a
 
      10-05-2004
Eric Brunel wrote:
> duikboot wrote:
>
>> Maboroshi wrote:
>>
>>> Hi I was curious how I can pass arguments through a Tkinter Entry widget
>>>
>>> say I have an Entry widget and a Button widget I enter text into the
>>> entry and now I want the button to process the text is there a
>>> certain command I have to use to assign the button to the entry or
>>> vise versa
>>>
>>> anyhelp appreciated

>>
>>
>>
>> Take a look at
>> http://www.pythonware.com/library/tk...tion/index.htm
>>
>> example
>>
>> from Tkinter import *
>>
>> def pr_text():
>> text = entry.get()
>> print text
>>
>> gui=Tk()
>> entry=Entry(gui)
>> entry.pack()
>> button=Button(gui, text="print", command=pr_text)
>> button.pack()
>>
>> gui.mainloop()

>
>
> If *that* is the actual problem, I'd use a Tkinter StringVariable to do
> the job:
>
> from Tkinter import *
> root = Tk()
> v = StringVar()
> Entry(root, textvariable=v).pack()
> def pr_text():
> print v.get()
> Button(root, text='Print', command=pr_text).pack()
> root.mainloop()
>
> Tkinter variables are a better choice because you often want to know
> what *was* in your entry after it has been destroyed from the display.
> In such a case, entry.get() will raise a TclError, because the entry no
> more exists. If you use a variable, it will still be there after the
> entry was destroyed, so you can still read its value.
>
> HTH


You're absolutely right. It's better indeed.

--
http://www.baandersconsultancy.nl | http://www.nosonis.com
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: What is the differences between tkinter in windows and Tkinter inthe other platform? Hidekazu IWAKI Python 0 12-15-2009 05:58 AM
What is the differences between tkinter in windows and Tkinter in theother platform? Hidekazu IWAKI Python 1 12-14-2009 03:44 PM
from Tkinter import *,win = Tk() "from Tkinter import *" Pierre Dagenais Python 0 08-03-2008 10:33 PM
Re: [Tkinter-discuss] Please help -- Tkinter Scale widget withDoubleVar is acting weird Jeff Epler Python 0 08-23-2004 02:31 PM
Re: [Tkinter-discuss] Please help -- Tkinter Scale widget withDoubleVar is acting weird Jeff Epler Python 0 08-20-2004 12:07 PM



Advertisments