473,322 Members | 1,405 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

How to add a drop down box in Python GUI

Hi,

How do i add a drop down box with few pre-populated strings in the same?
I could find list box and drop down menu in the HELP document of Python, but not drop down box.

Please help me in this.

Thanks,
BK
Nov 27 '06 #1
11 24177
bartonc
6,596 Expert 4TB
Hi,

How do i add a drop down box with few pre-populated strings in the same?
I could find list box and drop down menu in the HELP document of Python, but not drop down box.

Please help me in this.

Thanks,
BK
Tkinter does not have a combobox. If you are using Tkinter, I can supply a module that requires Python Image Library to make a drop-down menu + a text entry + graphics look like a combo box, but it may need some work first. I now use wxPython for GUI.
Nov 27 '06 #2
Tkinter does not have a combobox. If you are using Tkinter, I can supply a module that requires Python Image Library to make a drop-down menu + a text entry + graphics look like a combo box, but it may need some work first. I now use wxPython for GUI.

If that is so, could u please help me in this regard. Are there any pre requisites for the issue?

Thanks,
BK
Nov 27 '06 #3
bartonc
6,596 Expert 4TB
If that is so, could u please help me in this regard. Are there any pre requisites for the issue?

Thanks,
BK
I am unclear on which issue you want help with.
Nov 27 '06 #4
Hi,

My intention is to have a drop down box (with edit facility) which would have several ip addresses. The user either can select an existing one or else type a new ip.

I could find spinbox option but thats not editable.

So how do i create such a drop down box?

Thanks,
Badri
Nov 28 '06 #5
bartonc
6,596 Expert 4TB
Hi,

My intention is to have a drop down box (with edit facility) which would have several ip addresses. The user either can select an existing one or else type a new ip.

I could find spinbox option but thats not editable.

So how do i create such a drop down box?

Thanks,
Badri
You still have not said which GUI you are using. If you are using Tkinter, I can supply a class, but it will take me some time to make it work for you.
Nov 28 '06 #6
You still have not said which GUI you are using. If you are using Tkinter, I can supply a class, but it will take me some time to make it work for you.
Yes, I am using Tkinter.
Nov 28 '06 #7
bartonc
6,596 Expert 4TB
Yes, I am using Tkinter.
Ok, I'll tweek my module to work for you.
Nov 28 '06 #8
Would you include the code so everyone could benefit?


Ok, I'll tweek my module to work for you.
Mar 29 '07 #9
bartonc
6,596 Expert 4TB
Would you include the code so everyone could benefit?
Yep. I'll get right on it.
Mar 29 '07 #10
bartonc
6,596 Expert 4TB
Yep. I'll get right on it.
As promised:
Expand|Select|Wrap|Line Numbers
  1. from Tkinter import *
  2.  
  3. ## I have a working ComboBox which is editable and
  4. ## has a button around here some where. I'll keep
  5. ## looking for that. In the mean time, this Entry
  6. ## subclass shares a StringVar with the menu item
  7. ## that are created form input list(s) to achive a
  8. ## simple ChoiceBox.
  9.  
  10. class ChoiceBox(Entry):
  11.     """ComboBox(parent, itemList=[], *args, kwargs)
  12.        A simple ChoiceBox with checked menu items
  13.        itemList may be a mix of list of strings and lists of tuples of (label, list of strings)
  14.        for one level of sub menu items. *args and kwargs are passed to the Entry widget."""
  15.  
  16.     def __init__(self, parent, itemList=[], *args, **kwargs):
  17.         Entry.__init__(self, parent, *args, **kwargs)
  18.  
  19.         self.pyvar = pyvar = StringVar(self)    # this is the sharing mechanism
  20.         self.config(textvariable=pyvar)         # add the StringVar to self.
  21.  
  22.         self.popup = popup = Menu(self, tearoff=0)
  23.         self.bind("<Button-1>", self.mousedown, add="+")
  24.  
  25.         for item in itemList:
  26.             if type(item) == tuple:
  27.                 submenu = self.GetSubMenu(item[0])
  28.                 for subitem in item[1]:
  29.                     self.AddCBMenuItem(submenu, subitem)
  30.             else:
  31.                 self.AddCBMenuItem(popup, item)
  32.  
  33.     def GetSubMenu(self, label):
  34.         menu = Menu(self, tearoff=0)
  35.         self.popup.add_cascade(menu=menu, label=label)
  36.         return menu
  37.  
  38.     def AddCBMenuItem(self, menu, label):
  39.         menu.add_checkbutton(label=label,
  40.                              command=self.MenuSelect,
  41.                              variable=self.pyvar,   # add the StringVar to a menu.
  42.                              onvalue=label, offvalue='')
  43.  
  44.     def mousedown(self, event):
  45.         x = event.x_root - event.x
  46.         y = event.y_root -  event.y
  47.         self.popup.post(x, y)
  48.         return 'break'
  49.  
  50.     def get(self):
  51.         return self.pyvar.get()
  52.  
  53.     def clear(self):
  54.         self.pyvar.set('')
  55.  
  56.     def MenuSelect(self):
  57.         pass
  58.  
  59.  
  60.  
  61. if __name__ == '__main__':
  62.  
  63.  
  64.  
  65.     def _test():
  66.         root = Tk()
  67. ##        cb = ChoiceBox(root, [('test', ['one', 'two', 'three'])])
  68.         cb = ChoiceBox(root, ['one', 'two', 'three'])
  69.         cb.pack()
  70.         root.mainloop()
  71.  
  72.     _test()
  73.  
Mar 29 '07 #11
Cool code, but I don't see how to enable typing in a new entry...?
Apr 3 '15 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: PT | last post by:
I got a form with many text boxes, checkboxes and 3 drop downs. From that 3, 2 are dependant. I can choose one drop down, and the next drop down should display the dependant values of the first...
2
by: ehm | last post by:
I am working on creating an editable grid (for use in adding, deleting, and editing rows back to an Oracle database). I have a JSP that posts back to a servlet, which in turns posts to a WebLogic...
3
by: Don Wash | last post by:
Hi There! I have a Server-side Drop-down box in ASP.NET (VB) page. What do I do to widen the Drop down box's Pull-Down list's width? I'm not talking about the Drop-down box's width but the box...
2
by: Yoshitha | last post by:
hi I have 2 drop down lists in my application.1st list ontains itmes like java,jsp,swings,vb.net etc.2nd list contains percentage i.e it conatains the items like 50,60,70,80,90,100. i will...
4
by: Alex Hunsley | last post by:
Can anyone recommend some code for creating drop-down menus in tkinter? To be absolutely clear, here's an example of a drop-down: http://www.google.co.uk/preferences?hl=en (see the language...
3
by: bruce | last post by:
Hi... Never used python, but I have a question regarding Drop Down Menus. Does Python allow me to create a website, that will permit the user to create Drop Down menus that can be initiated with...
7
by: callawayglfr | last post by:
I am building a database in access where I have a drop down box that relates to a text box, that part I have working but when someone selects information from the first drop down I need it to limit...
4
by: TycoonUK | last post by:
Hi, As I do not have IE7 on my computer, I was wondering if there is a fault in my CSS Menu when using IE7. Please can someone look at my site - http://www.worldofmonopoly.co.uk and tell me...
3
by: penny111 | last post by:
Hi there, For my application, i need to have 3 drop down lists 1. drop down list of folder names 2. drop down list of documents in the folder selected 3. drop down list of instances of the...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.