473,782 Members | 2,525 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Default value for Listbox (Tkinter)

Whenever I set up something similar:

vals = ['1', '2','3']
for v in vals:
listbox.inset(E ND, v)

I notice that when this listbox is displayed, there is never a default
value. How can I make sure that one of the indices is selected by
default?

Thanks,

Harlin

Jul 18 '05 #1
2 11578
Harlin Seritt wrote:
Whenever I set up something similar:

vals = ['1', '2','3']
for v in vals:
listbox.inset(E ND, v)

I notice that when this listbox is displayed, there is never a default
value. How can I make sure that one of the indices is selected by
default?


Hi Harlin,

you must use the select_set method of the listbox.

---
from Tkinter import *

root = Tk()
listbox = Listbox(root)
listbox.pack()

vals = ['1', '2','3']
for v in vals:
listbox.insert( END, v)

listbox.select_ set(0) # sets the first element

root.mainloop()
---

Some good resources for Tkinter:
http://www.pythonware.com/library/tk...tion/index.htm
http://infohost.nmt.edu/tcc/help/pubs/tkinter/

HTH
Jørgen Cederberg
Jul 18 '05 #2
Thanks Jorgen!

I was reading the Tkinter tutorial (I was looking at this particular
page:
http://www.pythonware.com/library/tk...13-methods.htm)
and saw this for select_set():
select_set(inde x), select_set(firs t, last)
Add one or more items to the selection.
I think this was why I overlooked it. The description for it says the
listbox adds one or more items to a selection. I would think the
description should say the listbox sets the index or element.

Thanks again,

Harlin

Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
5829
by: Jørgen Hansen | last post by:
Hi I have a problem with a Listbox in Tkinter. When I tab through several widgets with the tab-key, the listbox looses its selection, even though it has been selected with .selection_set. The example below demonstrates this. Can anyone provide me with some help on this? Regards Jorgen
2
3808
by: Nicolas Favre-Félix | last post by:
Hello, I have a little problem using Tkinter: I'd like to make a interface with 3 labels on the left, facing with 3 Entry on the right, a button below Entrys, and a Listbox under all. I could place the Labels and Entrys, but the Listbox is just in column 0, and I want it to take all the width (column 0 + column 1) here is the code: #########################
2
5139
by: Zhang Le | last post by:
Hello, Is there a quick way to replace the content of a single item in tkinter's listbox? Currently my solution is to first delete the item, then insert a new item at the same position. I think there may be better way. Zhang Le
1
2778
by: Ebba Cecilia Ovesdotter Alm | last post by:
Hello, I'm learning how to use the Tkinter module. I would like to use an element similar to a drop-down form, where the user can select one option out of many. I thought that a Listbox item could do just this. The following extract from my code (with the listbox part basically mirroring http://effbot.org/books/tkinterbook/listbox.htm), does, however, not create a visable Listbox. Am I interpreting the Listbox incorrectly? Ideas or...
3
2581
by: vedran_dekovic | last post by:
Hi, I need help about Tkinter listbox widget.I want,when somebody click on any item(file) in Listbox,then in new Label widget text must be selected item from server. my program (wrong example): import ftputil import Tkinter root=Tkinter.Tk()
4
6140
by: rn5a | last post by:
I am binding a DropDownList with records existing in a database table. I want to add an extra item *SELECT COMPANY* at index 0 so that by default, it gets selected. This is how I tried it but the extra item just doesn't get added to the DropDownList: ============================================= <script runat="server"> Sub Page_Load(..........) Dim dSet As DataSet Dim sqlConn As SqlConnection
2
2098
by: Steve Potter | last post by:
I am trying to find some method of attaching a Listbox object to a list object so as the contents of the list are changed the contents of the Listbox will be updated to match. I have found a few references to something like this in this old post http://groups.google.com/group/comp.lang.python/browse_thread/thread/3a6fe7534c812f55/43f201ab53cfdbf7 as well as here http://effbot.org/zone/wck-4.htm . It just seems that there should be some...
2
1761
by: Ben Collver | last post by:
I am using Darwin 10.4.9, tcl 8.4.7, tk 8.4, and python 2.3.5. I have also tried Python 2.5 on Darwin, Debian, and Fedora Core 6. I am working on a GUI front-end to a Python program of mine. It is a simple grid with labels in the left column and input widgets in the right column. One of the rows has a listbox in the right column. The listbox contains two items. I select one using widget.select_set(). The GUI is not complete yet,...
2
2918
by: Appu2008 | last post by:
Hi, Iam using Python 2.5 and developing an application using Tkinter. I want a listbox with scrollbar. I tried to combine both but it gets filled in the entire screen. Here is the code.. frm=Frame(root,height=400,width=400) frm.pack() scrollbar1=Scrollbar(frm)
0
9641
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10146
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10080
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6735
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4044
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2875
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.