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) 3 6684
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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
|
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?
|
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...
|
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
______________________
| |
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;
|
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?
|
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 ?
|
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...
|
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...
|
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...
| |
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,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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();...
|
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...
|
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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |