943,584 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Marked Solved
  • Views: 8357
  • Python RSS
Mar 8th, 2006
0

Dropdown box in Python

Expand Post »
hi, i am very new in python. can anyone tell me that how to create dynamic dropdown box in python scripting.(triple dropdown box)
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sharma_vivek82 is offline Offline
18 posts
since Mar 2006
Mar 8th, 2006
0

Re: Dropdown box in Python

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.
Reputation Points: 625
Solved Threads: 211
Posting Virtuoso
Ene Uran is offline Offline
1,704 posts
since Aug 2005
Mar 9th, 2006
0

Re: Dropdown box in Python

i am working in ubuntu linux. and using python 2.4.2.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sharma_vivek82 is offline Offline
18 posts
since Mar 2006
Mar 9th, 2006
0

Re: Dropdown box in Python

simple code for creating dropdown box using javascript.
the html code for this, is
Python Syntax (Toggle Plain Text)
  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

Python Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sharma_vivek82 is offline Offline
18 posts
since Mar 2006
Mar 9th, 2006
0

Re: Dropdown box in Python

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)
  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.
Moderator
Reputation Points: 1333
Solved Threads: 1403
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: I Need Help Please Writing This Program
Next Thread in Python Forum Timeline: Avoid space in print





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC