473,695 Members | 2,224 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Searching for a ComboBox for Tkinter?

I've created a ghetto-ized ComboBox that should work nicely for Tkinter
(unfortunately no dropdown capabilities yet).

I've found why it's such a pain in the @ss to create one. You have to
re-create common methods and make sure they're mapped to the right
component (inside this widget are frame, entry, listbox, and scrollbar
widgets). I tried to look for ways I could inherit some methods from
other widgets but couldn't think of how to do it in an efficient way.

If anyone has suggestions to improve it, please respond... Remember...
I'm a traditional c/c++ turned python programmer who forgets that there
usually is a better, faster more graceful way to do things with Python
than with C/C++/Java.

Cheers,

Harlin

############### ############### ############### ############### ##########
# Seritt Extensions:
# Date: 02262005
# Class ComboBox
# Add this section to your Tkinter.py file in 'PYTHONPATH/Lib/lib-tk/'
# Options: width, border, background, foreground, fg, bg, font
# , relief, cursor, exportselection , selectbackgroun ,
selectforegroun d, height
#
# Methods: activate(int index) => int, curselection() => int,
delete(item=["ALL" or int], start=int, end=["END" or
# int],
# focus_set()/focus(), get()=>selected string in box, pack(padx=int,
pady=int, fill(X, Y, BOTH), expand=bool, # side=LEFT,
# RIGHT, TOP, BOTTOM, CENTER
#

class ComboBox:
ITEMS = range(0)

def activate(self, index):
self.listbox.ac tivate(index)

def curselection(se lf):
return map(int, self.listbox.cu rselection())[0]

def delete(self, item=None, start=None, end=None):
if item=='ALL':
self.listbox.de lete(0, END)
elif start == None and end == None:
self.listbox.de lete(item)
else:
self.listbox.de lete(start, end)

def get_focus(self) :
self.entry.get_ focus()

def focus(self):
self.entry.get_ focus()

def get(self):
return self.entry.get( )

def pack(self, padx=None, pady=None, fill=None, expand=None,
side=None):
self.frame.pack (padx=padx
, pady=pady
, fill=fill
, expand=expand
, side=side)

def size(self):
return self.listbox.si ze()

def insert(self, START, ITEM):
self.ITEMS.appe nd(ITEM)
self.listbox.in sert(START, ITEM)
self.listbox.se lect_set(0)
self.entry.dele te(0, END)
self.entry.inse rt(0, self.listbox.ge t(self.listbox. curselection()) )

def change_entry(se lf, event):
def i(event):
try:
self.entry.dele te(0, END)
self.entry.inse rt(0, self.listbox.ge t(self.listbox. curselection()) )
except:
pass
self.listbox.bi nd("<ButtonRele ase-1>", i)

def __init__(self, parent, width=None, border=1, background=None ,
foreground=None , fg=None, bg=None, font=None
, relief=None, cursor=None, exportselection =None,
selectbackgroun =None, selectforegroun d=None, height=None):
self.frame = Frame(parent)
self.entry = Entry(self.fram e
, width=None
, border=border
, background=back ground
, foreground=fore ground
, fg=fg
, bg=bg
, font=font
, relief=relief
, cursor=cursor
, exportselection =exportselectio n
, selectbackgroun =selectbackgrou n
, selectforegroun d=selectforegro und
, height=height)
self.entry.pack (fill=X)
self.scroll = Scrollbar(self. frame)
self.scroll.pac k(side=RIGHT, fill=Y)
self.listbox = Listbox(self.fr ame
, yscrollcommand= self.scroll.set
, width=None
, border=border
, background=back ground
, foreground=fore ground
, fg=fg
, bg=bg
, font=font
, relief=relief
, cursor=cursor
, exportselection =exportselectio n
, selectbackgroun =selectbackgrou n
, selectforegroun d=selectforegro und
, height=height)
self.listbox.pa ck(fill=X)
self.scroll.con fig(command=sel f.listbox.yview )
self.listbox.bi nd("<ButtonPres s-1>", self.change_ent ry)

Jul 18 '05 #1
3 6690
Or if you prefer you can download it here:
http://www.seritt.org/pub/tkinter/Tkinter-03132005.py

Replace your Tkinter.py with this one. Make sure you back up your old
one in case you decide mine sucks.

Thanks,

Harlin

Jul 18 '05 #2
Thanks nirinA... I've played with that one before. I'm not a big fan of
Pmw or Tix so much I guess although when it gets down to it, those
'extra' toolkits are probably more functional.

Cheers,

Harlin

Jul 18 '05 #3
ahh Frame! I didn't even think of extending Frame. I kept wondering how
I could instead extend entry and listbox... thanks for the pointer.
Yeah I know there are others out there, I just wanted to create one
from tkinter widgets and keep the constructor as close to other tkinter
widgets as possible. I notice that when you use Pmw you have different
option names and methods that are a bit inconsistent (not too hard to
remember though--it's not a criticism of Pmw or Tix). I am very
narrow-minded. :-)

As far as the other lists/wiki, I will be looking at them.

Thanks,

Harlin

Jul 18 '05 #4

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

Similar topics

1
5980
by: Josh | last post by:
Caution, newbie approaching... I'm trying to come up with a very simple Tkinter test application that consists of a window with a drop-down menu bar at the top and a grid of colored rectangles filling the remainder of the window. Mind you, this is a contrived test application to help me understand Tkinter and Python, not an actual application yet. I've trivially subclassed Tkinter.Canvas into ColorCanvas, added a bunch of ColorCanvases...
3
3701
by: Peter Moscatt | last post by:
Does Tkinter provide a combobox or do I have to find some way of making a listbox do the job ? Pete
0
1269
by: “ √……Ĺ»ň | last post by:
i have not find the ComboBox in Tkinter,has it? where to get the doc about how to use combobox ctrl?
0
3581
by: syed_saqib_ali | last post by:
Below is a simple code snippet showing a Tkinter Window bearing a canvas and 2 connected scrollbars (Vertical & Horizontal). Works fine. When you shrink/resize the window the scrollbars adjust accordingly. However, what I really want to happen is that the area of the canvas that the scrollbars show (the Scrollregion) should expand as the window grows. It doesn't currently do this. although, if the window shrinks smaller than the...
8
1600
by: David | last post by:
Hi, I have a form as follows: Main Form (To Select Customer) Sub Form 1 (To Select PO Number, by clicking on field) - Continuous form Sub Form 2 (To view order details)- Continuous form ______________________
5
4138
by: Andy | last post by:
I am having trouble using the ComboBox in my app. I am attempting to use the text from the ComboBox, to search the list box portion. However: In my "TextChanged" event: I cannot get the value of the entered text. Below is my code. private void cbEdit_TextChanged(object sender, System.EventArgs e) { bool bFound = false; string sText = cbEdit.Text; int iPosition = cbEdit.SelectionStart;
1
3596
by: Michael Yanowitz | last post by:
Hello: Below I have included a stripped down version of the GUI I am working on. It contains 2 dialog boxes - one main and one settings. It has the following problems, probably all related, that I am hoping someone knows what I am doing wrong: 1) Pressing the Settings.. Button multiple times, brings up many instances of the Settings Panel. I just want it to bring up one. Is there an easy way to do that?
8
3284
by: karthikbalaguru | last post by:
Hi, One of my python program needs tkinter to be installed to run successfully. I am using Redhat 9.0 and hence tried installing by copying the tkinter-2.2.2-36.i386.rpm alone from the CD 3 to my pc. But, it is not getting installed and is failing by throwing the below errors. Should i need to configure / install any specific files for resolving this issue ?
3
2981
by: joshdw4 | last post by:
I hate to do this, but I've thoroughly exhausted google search. Yes, it's that pesky root window and I have tried withdraw to no avail. I'm assuming this is because of the methods I'm using. I guess my question is two-fold. 1) How do I get rid of that window? 2) Any comments in general? I am just learning python (and coding with classes), so I'm sure there are things I should pound into my head before I learn bad habits. Here's the...
0
8623
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
9113
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8976
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
8830
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,...
0
7655
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectóplanning, coding, testing, and deploymentówithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5837
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
4339
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4575
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2997
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

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.