Dropdown box in Python

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Mar 2006
Posts: 18
Reputation: sharma_vivek82 is an unknown quantity at this point 
Solved Threads: 0
sharma_vivek82 sharma_vivek82 is offline Offline
Newbie Poster

Dropdown box in Python

 
0
  #1
Mar 8th, 2006
hi, i am very new in python. can anyone tell me that how to create dynamic dropdown box in python scripting.(triple dropdown box)
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 1,546
Reputation: Ene Uran has a spectacular aura about Ene Uran has a spectacular aura about 
Solved Threads: 174
Ene Uran's Avatar
Ene Uran Ene Uran is offline Offline
Posting Virtuoso

Re: Dropdown box in Python

 
0
  #2
Mar 8th, 2006
What GUI library are you using? I am a little familiar with Tkinter and wxPython and might be able to help. There are others I am not familiar with.
drink her pretty
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 18
Reputation: sharma_vivek82 is an unknown quantity at this point 
Solved Threads: 0
sharma_vivek82 sharma_vivek82 is offline Offline
Newbie Poster

Re: Dropdown box in Python

 
0
  #3
Mar 9th, 2006
i am working in ubuntu linux. and using python 2.4.2.
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 18
Reputation: sharma_vivek82 is an unknown quantity at this point 
Solved Threads: 0
sharma_vivek82 sharma_vivek82 is offline Offline
Newbie Poster

Re: Dropdown box in Python

 
0
  #4
Mar 9th, 2006
simple code for creating dropdown box using javascript.
the html code for this, is
  1. <html>
  2. <head>
  3. <title></title>
  4. <script language="javascript" src="list.js"></script>
  5. </head>
  6.  
  7. <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000" onload="fillCategory();">
  8.  
  9. <FORM name="drop_list" >
  10.  
  11. <SELECT NAME="Category" onChange="SelectDistrict();" >
  12. <Option value="">States</option>
  13. </SELECT>&nbsp;
  14. <SELECT id="District" NAME="District" onChange="SelectCollege();">
  15. <Option value="">Districts</option>
  16.  
  17. </SELECT>
  18. <SELECT id="College" NAME="College">
  19. <Option value="">College</option>
  20. </SELECT>
  21. <input type="button" name="go" value="Value Selected"
  22. onclick="alert(document.drop_list.College.options[document.drop_list.College.selectedIndex].value);">
  23. </form>
  24.  
  25. </body>
  26.  
  27. </html>

here i am calling javascript writen in another file list.js. The content of list.js is following

  1. function fillCategory(){
  2.  
  3. // this function is used to fill the category list on load
  4.  
  5. addOption(document.drop_list.Category, "Karnataka", "Karnataka", "");
  6.  
  7. addOption(document.drop_list.Category, "Jharkhand", "Jharkhand", "");
  8.  
  9. addOption(document.drop_list.Category, "Hariyana", "Hariyana", "");
  10.  
  11. }
  12.  
  13.  
  14. function SelectDistrict(){
  15.  
  16. // ON selection of category this function will work
  17.  
  18.  
  19. removeAllOptions(document.drop_list.District);
  20. addOption(document.drop_list.District, "", "District", "");
  21.  
  22.  
  23. if(document.drop_list.Category.value == 'Karnataka'){
  24. addOption(document.drop_list.District,"Bangalore", "Bangalore");
  25. addOption(document.drop_list.District,"Kolar", "Kolar");
  26. addOption(document.drop_list.District,"Hubali", "Hubali");
  27. }
  28. if(document.drop_list.Category.value == 'Jharkhand'){
  29. addOption(document.drop_list.District,"Ranchi", "Ranchi");
  30. addOption(document.drop_list.District,"Jamshedpur", "Jamshedpur");
  31. addOption(document.drop_list.District,"Hazbagh", "Hazbagh", "");
  32. }
  33. if(document.drop_list.Category.value == 'Hariyana'){
  34. addOption(document.drop_list.District,"Noida", "Noida");
  35. addOption(document.drop_list.District,"Gurgaon", "Gurgaon");
  36. addOption(document.drop_list.District,"Panipat", "Panipat");
  37. }
  38.  
  39. }
  40.  
  41. function SelectCollege(){
  42.  
  43. // ON selection of District this function will work
  44.  
  45.  
  46. removeAllOptions(document.drop_list.College);
  47. addOption(document.drop_list.College, "", "College", "");
  48.  
  49.  
  50. if(document.drop_list.District.value == 'Bangalore'){
  51. addOption(document.drop_list.College,"BIT Bangalore", "BIT Bangalore");
  52. addOption(document.drop_list.College,"MVIT Bangalore", "MVIT Bangalore");
  53. }
  54. if(document.drop_list.District.value == 'Kolar'){
  55. addOption(document.drop_list.College,"BIT Kolar", "BIT Kolar");
  56. addOption(document.drop_list.College,"BIT Kolar", "BIT Kolar");
  57. }
  58. if(document.drop_list.District.value == 'Hubali'){
  59. addOption(document.drop_list.College,"YMCA", "YMCA");
  60. addOption(document.drop_list.College,"IIT", "IIT");
  61. }
  62. if(document.drop_list.District.value == 'Ranchi'){
  63. addOption(document.drop_list.College,"ZXA", "ZXA");
  64. addOption(document.drop_list.College,"DSA", "DSA");
  65. }
  66. if(document.drop_list.District.value == 'Jamshedpur'){
  67. addOption(document.drop_list.College,"QWE", "QWE");
  68. addOption(document.drop_list.College,"ZXC", "ZXC");
  69. }
  70. if(document.drop_list.District.value == 'Hazbagh'){
  71. addOption(document.drop_list.College,"ZDC", "ZDC");
  72. addOption(document.drop_list.College,"FGV", "FGV");
  73. }
  74. if(document.drop_list.District.value == 'Noida'){
  75. addOption(document.drop_list.College,"uio", "uio");
  76. addOption(document.drop_list.College,"klj", "klj");
  77. }
  78. if(document.drop_list.District.value == 'Gurgaon'){
  79. addOption(document.drop_list.College,"yhn", "yhn");
  80. addOption(document.drop_list.College,"fgh", "fgh");
  81. }
  82. if(document.drop_list.District.value == 'Panipat'){
  83. addOption(document.drop_list.College,"olm", "olm");
  84. addOption(document.drop_list.College,"bnm", "bnm");
  85. }
  86. }
  87. //////////////////
  88.  
  89.  
  90.  
  91. function removeAllOptions(selectbox)
  92.  
  93. {
  94.  
  95. var i;
  96.  
  97. for(i=selectbox.options.length-1;i>=0;i--)
  98.  
  99. {
  100.  
  101. //selectbox.options.remove(i);
  102.  
  103. selectbox.remove(i);
  104.  
  105. }
  106.  
  107. }
  108.  
  109.  
  110.  
  111.  
  112.  
  113. function addOption(selectbox, value, text )
  114.  
  115. {
  116.  
  117. var optn = document.createElement("OPTION");
  118.  
  119. optn.text = text;
  120.  
  121. optn.value = value;
  122.  
  123.  
  124.  
  125. selectbox.options.add(optn);
  126.  
  127. }

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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,109
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 943
Moderator
vegaseat's Avatar
vegaseat vegaseat is online now Online
DaniWeb's Hypocrite

Re: Dropdown box in Python

 
0
  #5
Mar 9th, 2006
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!
  1. # the wxChoice() widget, a simple dropdown box
  2. # wx.Choice(parent, id, pos, size, choices, style)
  3. # tested with Python24 and wxPython26
  4. # should work on Windows, Linux, and Unix systems
  5.  
  6. import wx
  7.  
  8. class MyFrame(wx.Frame):
  9. """ class MyFrame inherits wxFrame, uses default ID of -1"""
  10. def __init__(self ):
  11. wx.Frame.__init__(self, None, -1, 'wxChoice test', size=(300, 150))
  12.  
  13. colorList = ['red', 'green', 'blue', 'yellow','white']
  14. # create the dropdown box
  15. self.choice1 = wx.Choice(self, -1, choices=colorList)
  16. # select item 1 = 'green' to show
  17. self.choice1.SetSelection(1)
  18. # set focus to receive optional keyboard input
  19. # eg. type r for red, y for yellow
  20. self.choice1.SetFocus()
  21. # new event handler wxPython version 2.5 and higher
  22. self.choice1.Bind(wx.EVT_CHOICE, self.onChoice)
  23.  
  24. def onChoice(self, event):
  25. '''get the slected color choice'''
  26. self.color = self.choice1.GetStringSelection()
  27. self.SetTitle(self.color) # test
  28.  
  29.  
  30. # this is only a small application
  31. application = wx.PySimpleApp()
  32. # call class MyFrame
  33. frame1 = MyFrame()
  34. # show the frame
  35. frame1.Show(True)
  36. # start the event loop
  37. application.MainLoop()
Last edited by vegaseat; Aug 12th, 2009 at 5:44 pm.
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for Python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC