The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Python Programming
|
Listbox with Scrollbar
Discuss Listbox with Scrollbar in the Python Programming forum on Dev Shed. Listbox with Scrollbar Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

December 21st, 2012, 11:25 AM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 7
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.
|

December 21st, 2012, 12:42 PM
|
 |
Contributing User
|
|
|
|
__________________
[code] Code tags[/code] are essential for python code!
|

December 21st, 2012, 01:43 PM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 7
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.
|

December 21st, 2012, 01:56 PM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 7
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.
|

December 21st, 2012, 04:13 PM
|
|
Contributing User
|
|
Join Date: May 2009
Posts: 313
  
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.
|

December 21st, 2012, 04:18 PM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 7
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.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|