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 December 21st, 2012, 11:25 AM
xsilvergs xsilvergs is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 7 xsilvergs User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 45 m 48 sec
Reputation Power: 0
Listbox with Scrollbar

Hi.
New to Python so sorry if obvious question but after a day I can't work out the answer. The code below produces a scrollable listbox but I can't work out how to read the displayed value for use in an equation. I hope to have a few of these eventually.
Here is my code:
Code:
from Tkinter import *
master = Tk()

scrollbarKG = Scrollbar(master)
scrollbarKG.grid(row=0, column=1, sticky='NS')

listboxKG = Listbox(master, selectmode=SINGLE, yscrollcommand=scrollbarKG.set, height=1, width='3')
for i in xrange(50, 150):
    listboxKG.insert(END, i)
listboxKG.grid(row=0, column=0)
scrollbarKG.config(command=listboxKG.yview)
mainloop()

There will probably be a button to click once all data has been selected via the listboxes.
Thanks in advance for any help.

Reply With Quote
  #2  
Old December 21st, 2012, 12:42 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,458 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 4 Days 6 h 26 m 43 sec
Reputation Power: 403
Does this Scale widget reference help?

http://effbot.org/tkinterbook/scale.htm
__________________
[code]Code tags[/code] are essential for python code!

Reply With Quote
  #3  
Old December 21st, 2012, 01:43 PM
xsilvergs xsilvergs is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 7 xsilvergs User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 45 m 48 sec
Reputation Power: 0
Quote:
Does this Scale widget reference help?


I'll take a look, this is all very new.

Reply With Quote
  #4  
Old December 21st, 2012, 01:56 PM
xsilvergs xsilvergs is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 7 xsilvergs User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 45 m 48 sec
Reputation Power: 0
Hum!

Not really what I want. In this instance the idea was for the user to select their weight, anything between 50 and 150 Kgs. Their weight would then go into an equation.

I was trying this as opposed to them entering their weight and then having to error check to ensure it was a integer etc.

EDIT:
A Spinbox may work but once again how do you get the value?

Hope that gives more info.

Reply With Quote
  #5  
Old December 21st, 2012, 04:13 PM
dwblas dwblas is online now
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2009
Posts: 313 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 23 h 17 m 27 sec
Reputation Power: 7
Generally you bind ListboxSelect to a callback then use curselection()
Code:
from Tkinter import *

def get_weight(event):
    index = listboxKG.curselection()  
    value = listboxKG.get(index)
    print index, value

master = Tk()
master.geometry("100x100")

scrollbarKG = Scrollbar(master)
scrollbarKG.grid(row=0, column=1, sticky='NS')

listboxKG = Listbox(master, selectmode=SINGLE, yscrollcommand=scrollbarKG.set, height=5, width='3')
for i in xrange(50, 150):
    listboxKG.insert(END, i)
listboxKG.grid(row=0, column=0)
listboxKG.bind('<<ListboxSelect>>', get_weight)

scrollbarKG.config(command=listboxKG.yview)

mainloop() 
If you install the PMW extension to Tkinter and use the ScrolledListBox you won't have to mess with adding scroll bars.

Last edited by dwblas : December 21st, 2012 at 04:19 PM.

Reply With Quote
  #6  
Old December 21st, 2012, 04:18 PM
xsilvergs xsilvergs is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 7 xsilvergs User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 45 m 48 sec
Reputation Power: 0
Like this:
Code:
from Tkinter import *
import tkMessageBox

master = Tk()
def helloCallBack():
   tkMessageBox.showinfo( "Hello Python", var.get())
   
var = StringVar()
w = Spinbox(master, from_=50, to=150, textvariable=var, state="readonly")
w.pack()

e = Button(master, text='press', border='2', command = helloCallBack)
e.pack()

mainloop()


A bit messy but proves a point I think so will try again tomorrow. If anyone has any ideas please chip in.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Listbox with Scrollbar

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