472,352 Members | 1,538 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,352 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 23934
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...
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...
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...
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...
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: ...
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...
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...
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...
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...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

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.