| | |
Dropdown box in Python
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Mar 2006
Posts: 18
Reputation:
Solved Threads: 0
simple code for creating dropdown box using javascript.
the html code for this, is
here i am calling javascript writen in another file list.js. The content of list.js is following
this is very simple to understand it.
If any one have code to create dropdown box in Python script plz send me....
Edit: Added code tags vegaseat
the html code for this, is
Python Syntax (Toggle Plain Text)
<html> <head> <title></title> <script language="javascript" src="list.js"></script> </head> <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000" onload="fillCategory();"> <FORM name="drop_list" > <SELECT NAME="Category" onChange="SelectDistrict();" > <Option value="">States</option> </SELECT> <SELECT id="District" NAME="District" onChange="SelectCollege();"> <Option value="">Districts</option> </SELECT> <SELECT id="College" NAME="College"> <Option value="">College</option> </SELECT> <input type="button" name="go" value="Value Selected" onclick="alert(document.drop_list.College.options[document.drop_list.College.selectedIndex].value);"> </form> </body> </html>
here i am calling javascript writen in another file list.js. The content of list.js is following
Python Syntax (Toggle Plain Text)
function fillCategory(){ // this function is used to fill the category list on load addOption(document.drop_list.Category, "Karnataka", "Karnataka", ""); addOption(document.drop_list.Category, "Jharkhand", "Jharkhand", ""); addOption(document.drop_list.Category, "Hariyana", "Hariyana", ""); } function SelectDistrict(){ // ON selection of category this function will work removeAllOptions(document.drop_list.District); addOption(document.drop_list.District, "", "District", ""); if(document.drop_list.Category.value == 'Karnataka'){ addOption(document.drop_list.District,"Bangalore", "Bangalore"); addOption(document.drop_list.District,"Kolar", "Kolar"); addOption(document.drop_list.District,"Hubali", "Hubali"); } if(document.drop_list.Category.value == 'Jharkhand'){ addOption(document.drop_list.District,"Ranchi", "Ranchi"); addOption(document.drop_list.District,"Jamshedpur", "Jamshedpur"); addOption(document.drop_list.District,"Hazbagh", "Hazbagh", ""); } if(document.drop_list.Category.value == 'Hariyana'){ addOption(document.drop_list.District,"Noida", "Noida"); addOption(document.drop_list.District,"Gurgaon", "Gurgaon"); addOption(document.drop_list.District,"Panipat", "Panipat"); } } function SelectCollege(){ // ON selection of District this function will work removeAllOptions(document.drop_list.College); addOption(document.drop_list.College, "", "College", ""); if(document.drop_list.District.value == 'Bangalore'){ addOption(document.drop_list.College,"BIT Bangalore", "BIT Bangalore"); addOption(document.drop_list.College,"MVIT Bangalore", "MVIT Bangalore"); } if(document.drop_list.District.value == 'Kolar'){ addOption(document.drop_list.College,"BIT Kolar", "BIT Kolar"); addOption(document.drop_list.College,"BIT Kolar", "BIT Kolar"); } if(document.drop_list.District.value == 'Hubali'){ addOption(document.drop_list.College,"YMCA", "YMCA"); addOption(document.drop_list.College,"IIT", "IIT"); } if(document.drop_list.District.value == 'Ranchi'){ addOption(document.drop_list.College,"ZXA", "ZXA"); addOption(document.drop_list.College,"DSA", "DSA"); } if(document.drop_list.District.value == 'Jamshedpur'){ addOption(document.drop_list.College,"QWE", "QWE"); addOption(document.drop_list.College,"ZXC", "ZXC"); } if(document.drop_list.District.value == 'Hazbagh'){ addOption(document.drop_list.College,"ZDC", "ZDC"); addOption(document.drop_list.College,"FGV", "FGV"); } if(document.drop_list.District.value == 'Noida'){ addOption(document.drop_list.College,"uio", "uio"); addOption(document.drop_list.College,"klj", "klj"); } if(document.drop_list.District.value == 'Gurgaon'){ addOption(document.drop_list.College,"yhn", "yhn"); addOption(document.drop_list.College,"fgh", "fgh"); } if(document.drop_list.District.value == 'Panipat'){ addOption(document.drop_list.College,"olm", "olm"); addOption(document.drop_list.College,"bnm", "bnm"); } } ////////////////// function removeAllOptions(selectbox) { var i; for(i=selectbox.options.length-1;i>=0;i--) { //selectbox.options.remove(i); selectbox.remove(i); } } function addOption(selectbox, value, text ) { var optn = document.createElement("OPTION"); optn.text = text; optn.value = value; selectbox.options.add(optn); }
this is very simple to understand it.
If any one have code to create dropdown box in Python script plz send me....
Edit: Added code tags vegaseat
Last edited by vegaseat; Mar 9th, 2006 at 10:07 am.
Here is an example using wxPython. Once you have Python installed you need to download wxPython appropriate for your system and Python version, it's free!
python Syntax (Toggle Plain Text)
# the wxChoice() widget, a simple dropdown box # wx.Choice(parent, id, pos, size, choices, style) # tested with Python24 and wxPython26 # should work on Windows, Linux, and Unix systems import wx class MyFrame(wx.Frame): """ class MyFrame inherits wxFrame, uses default ID of -1""" def __init__(self ): wx.Frame.__init__(self, None, -1, 'wxChoice test', size=(300, 150)) colorList = ['red', 'green', 'blue', 'yellow','white'] # create the dropdown box self.choice1 = wx.Choice(self, -1, choices=colorList) # select item 1 = 'green' to show self.choice1.SetSelection(1) # set focus to receive optional keyboard input # eg. type r for red, y for yellow self.choice1.SetFocus() # new event handler wxPython version 2.5 and higher self.choice1.Bind(wx.EVT_CHOICE, self.onChoice) def onChoice(self, event): '''get the slected color choice''' self.color = self.choice1.GetStringSelection() self.SetTitle(self.color) # test # this is only a small application application = wx.PySimpleApp() # call class MyFrame frame1 = MyFrame() # show the frame frame1.Show(True) # start the event loop application.MainLoop()
Last edited by vegaseat; Aug 12th, 2009 at 5:44 pm.
May 'the Google' be with you!
![]() |
Similar Threads
- Please anybody help to create autocomplete dropdown box with editable in asp.net (ASP.NET)
- php dropdown box problem (PHP)
- model less dialog box (Python)
- I have a problem with python....help (Python)
- combo box (PHP)
Other Threads in the Python Forum
- Previous Thread: I Need Help Please Writing This Program
- Next Thread: Avoid space in print
| Thread Tools | Search this Thread |
Tag cloud for Python
accessdenied apache application argv beginner book change code color converter dictionary dynamic edit editing enter examples excel file filename float format ftp function gui homework import inches input java keyboard lapse library line lines linux list lists loop microphone mouse movingimageswithpygame mysql newb number numbers numeric output parameters parsing path phonebook port prime program programming projects py2exe pygame pyopengl pyqt python random recursion recursive redirect remote reverse scrolledtext server session simple smtp software sprite ssh statictext string strings syntax table tennis terminal text thread threading time tkinter tlapse trick tuple tutorial ubuntu unicode unit urllib urllib2 variable windows wordgame wxpython






