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 January 31st, 2013, 04:35 PM
Saffron Saffron is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 2 Saffron User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 m 25 sec
Reputation Power: 0
Tkinter problem

Hi,

I'm relatively new to Python and am building a GUI using Tkinter. As part of the GUI I have a form ("frm2") which has a number of enrty labels ("self.ent"). These are placed in the form using a double loop (see below). I also have a button which I want to return all the entries. The button is linked (i.e. using command=self.GetValues) to a function which uses self.entVar.get() to try and get all the entries but this only gives me the last entry. Any suggestions how I can get all the entries when the button is pressed?

frm2 = LabelFrame(cnv, text="Portfolio Weights:", font=("Calibri", 12), width=150)

#Frame contents
for i in range(0, len(Assets_Text)):
labi = Label(frm2, width=30, text=Assets_Text[i], anchor='w')
labi.grid(row=i+5, column=0, sticky='we')

for j in range(0, self.entry2Variable.get()):
lab2 = Label(frm2, text="Portfolio %d" % (j+1), width=10,
font=("Calibri", 10))
lab2.grid(row=4, column=j+1)

self.entVar = IntVar()
self.ent = Entry(frm2, width=10, textvariable=self.entVar)
self.ent.grid(row=i+5, column=j+1)
self.entVar.set(0.00)

Reply With Quote
  #2  
Old February 1st, 2013, 12:23 AM
dwblas dwblas is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2009
Posts: 291 dwblas User rank is Corporal (100 - 500 Reputation Level)dwblas User rank is Corporal (100 - 500 Reputation Level)dwblas User rank is Corporal (100 - 500 Reputation Level)dwblas User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 3 Days 18 h 24 m 25 sec
Reputation Power: 6
Each successive Entry box or Var over writes the previous. You have to save each one in a list or some other container. You code somewhat simplified since you omitted several parts, but working.
Code:
from Tkinter import *

root = Tk()

def get_values():
    for ent_var in entry_vars:
        print ent_var.get()

frm2 = LabelFrame(text="Portfolio Weights:", font=("Calibri", 12), width=150).grid()

#Frame contents
labi = Label(frm2, width=30, text="Label Test", anchor='w')
labi.grid(row=1, column=0, sticky='we')

Button(frm2, text="get values", command=get_values).grid(row=10, column=1)

entry_vars = []
for ctr in range(0, 5):
    lab2 = Label(frm2, text="Portfolio %d" % (ctr+1), width=10,
                             font=("Calibri", 10))
    lab2.grid(row=ctr+2, column=0)
                
    entVar = IntVar()
    ent = Entry(frm2, width=10, textvariable=entVar)
    ent.grid(row=ctr+2, column=1)
    entVar.set(0)
    entry_vars.append(entVar)
root,mainloop() 

Reply With Quote
  #3  
Old February 1st, 2013, 02:14 PM
Saffron Saffron is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 2 Saffron User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 m 25 sec
Reputation Power: 0
Thanks for your help dwblas.
Much appreciated.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Tkinter problem

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