Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 27th, 2012, 02:41 AM
philip_95 philip_95 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 5 philip_95 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 46 m 21 sec
Reputation Power: 0
Tkinter inpput box

i have a thinker input box and a button next to it how do i get the value in the input box to become a vrablie to use in the programe?

Reply With Quote
  #2  
Old November 27th, 2012, 08:35 AM
rrashkin's Avatar
rrashkin rrashkin is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Location: 39N 104.28W
Posts: 90 rrashkin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 13 h 41 m 29 sec
Reputation Power: 2
Quote:
Originally Posted by philip_95
i have a thinker input box and a button next to it how do i get the value in the input box to become a vrablie to use in the programe?

If by "input box" you mean "entry widget", there is a widget option (attribute), "textvariable". If you set this to a variable name,
Code:
self.<entry widget path>=Entry(frame, width=somewidth, textvariable=varname)
,
then presumably the value in the entry widget will be (as a string) the value of varname.

I find it easier however to just grab the contents when I want them and assign the variable accordingly:
Code:
varname=self.<entry widget path>.get()

Reply With Quote
  #3  
Old November 27th, 2012, 09:12 AM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,383 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 13 h 44 m 42 sec
Reputation Power: 383
Criminal that we must be careful with posts while you write careless slop.

And as rrashkin says, you didn't bother to indicate what is an "input box".
Code:
#Reference

import sys

try:
    import Tkinter as tkinter
except:
    import tkinter

top = tkinter.Tk()

t = tkinter.Text(top)
t.pack()
t.insert('1.0','The Text widget')

e = tkinter.Entry(top)
e.pack()
e.insert(0,'Entry widget')

class callback:

    '''
        Hmmm.  lamba is simple.
    '''

    keys = set('text entry'.split())

    def __init__(self,**kwargs):
        # force pretty construction.
        if not self.__class__.keys.issubset(set(kwargs)):
            raise ValueError(
                '%s(entry=EntryWidget,text=TextWidget)'%self.__class__.__name__)
        self.__dict__.update(kwargs)
        self.ouf = sys.stdout # open file ouf specifies the text and entry destination.

    def __call__(self,*args,**kwargs):
        w = self.ouf.write
        w('-'*40)
        w('\n'*2)
        w('Text box content:\n')
        # '1.0' specifies row 1, column 0, which is the start.
        w(self.text.get('1.0',tkinter.END))  ##########You're looking for this line
        w('\n')
        w('Entry box content: '+self.entry.get()) ################## and for this line also
        w('\n'*2)

tkinter.Button(top,
               text='write content to ouf',
               command=callback(text=t,entry=e)
               ).pack(side=tkinter.LEFT)
tkinter.Button(top,text='exit',command=top.destroy).pack(side=tkinter.RIGHT)

top.mainloop()
__________________
[code]Code tags[/code] are essential for python code!

Reply With Quote
  #4  
Old November 27th, 2012, 04:40 PM
Dietrich's Avatar
Dietrich Dietrich is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 483 Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Days 22 h 51 m 26 sec
Reputation Power: 63
Let's assume you want to do this:
Code:
'''tk_Entry_Button_simple.py
simple Tkinter Entry/Button example
'''

# with Python2 use 'import Tkinter as tk'
import tkinter as tk

def action():
    # get the entry value
    val = enter.get()
    # display it in the root title as a test
    root.title("name = %s" % val)


root = tk.Tk()
root.title("Enter your name")
# the entry
enter = tk.Entry(root, bg='yellow', width=50)
# the action button
button = tk.Button(root, text='Show name', command=action)

# pack widgets horizontally in the root window in order
enter.pack(side='left')
button.pack()

# start cursor in entry
enter.focus()

# start the event loop
root.mainloop()
Comments on this post
philip_95 agrees: this helped
__________________
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25

Reply With Quote
  #5  
Old November 27th, 2012, 08:54 PM
Brewzer Brewzer is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 9 Brewzer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 55 m 30 sec
Reputation Power: 0
Quote:
That is pretty cool! What if I wanted to calculate the monthly payment on an auto loan?

Code:
'Monthly Payment'

Reply With Quote
  #6  
Old November 29th, 2012, 02:43 AM
philip_95 philip_95 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 5 philip_95 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 46 m 21 sec
Reputation Power: 0
yes i mean entry box
thanks i try some of them

Reply With Quote
  #7  
Old November 30th, 2012, 04:51 AM
philip_95 philip_95 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 5 philip_95 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 46 m 21 sec
Reputation Power: 0
Quote:
Originally Posted by Dietrich
Let's assume you want to do this:
Code:
'''tk_Entry_Button_simple.py
simple Tkinter Entry/Button example
'''

# with Python2 use 'import Tkinter as tk'
import tkinter as tk

def action():
    # get the entry value
    val = enter.get()
    # display it in the root title as a test
    root.title("name = %s" % val)


root = tk.Tk()
root.title("Enter your name")
# the entry
enter = tk.Entry(root, bg='yellow', width=50)
# the action button
button = tk.Button(root, text='Show name', command=action)

# pack widgets horizontally in the root window in order
enter.pack(side='left')
button.pack()

# start cursor in entry
enter.focus()

# start the event loop
root.mainloop()


Thanks this helped

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Tkinter inpput box

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap