popen - reading strings - constructing a list from the strings

norseman norseman at hughes.net
Thu May 21 18:45:21 CEST 2009


MRAB wrote:
> Aytekin Vargun wrote:
>> First of all,
>> Thanks for the suggestions, MRAB and norseman. "split()" was what I 
>> was looking for. Now I have a follow up question. In my application I 
>> create radio buttons in a frame. These radio buttons are constructed 
>> whenever a button is clicked. Therefore the list of items are 
>> dynamically changing.
>>
>> What I want to do is to remove the current radio buttons and then 
>> recreate a new set of radio buttons using a new string list. I could 
>> not see a command for deleting or removing a set of radio buttons. I 
>> use Tkinter.
>>
>> I can provide more details.
>> Thanks a lot.
>>
>> PS: I apologize if this creates a new thread. I am new to the list.
>> Aytekin
>>
> I have no idea whether this is possible. I'd just create a new frame. I
> hope you're not trying to add and remove buttons on a dialog while it's
> open; having a dialog radically change its appearance while the user is
> watching would, IMHO, be very bad! :-)
==========================
"... be very bad.." NOPE.
When it's done right, it's quite an eye catcher.

Actually I use that very technique to great advantage.

             (excerpts from non-existent "How to Build a Control Panel")
Leave space for the changing frame in the root or topwindow.
define a frame to fit that space.
define the groups of buttons (static or dynamic) with each using the
   above frame as their home.  (many to one relation)
   put each button group in a def ...() of it's own.
   call the appropriate as needed


example:
             (to call the button(s))
if condition.....
  DispSubI()
else:
  DispSubNB()  #

where:
            (the content changing frame)
  def SubClas():
     try:
       frameSub.destroy()
     except:
       pass
     frameSub =   define your
     .             disposable frame
     .              template here
     label.pack()
     return frameSub


            (the buttons)
----------------------------------------------------------
   #
   #                           I - IDLE
   def DispSubI():
     frameSub= SubClas()
     I_SUB = [
       (" 1", "Land not cropped this and/or last season"),
       (" 2", "New lands being prepared for crop production"),
     ]
     #
     # ---------------------- BUTTONS
     #
     SubI= []
     for mode, text in I_SUB:
       c = Radiobutton(frameSub, text=text, indicatoron=0,
             variable=SubVal, value=mode, command=getSub)
       SubI.append(c)
       c.pack()
   #
   #
   # ----------------------------------------------------------
   #
   #                     NB - BARREN AND WASTELAND
   def DispSubNB():
     frameSub= SubClas()
     NB_SUB = [
       ("**", "None"),
       (" 1", "Dry stream channels"),
       (" 2", "Mine Tailing"),
       (" 3", "Barren land"),
       (" 4", "Salt flats"),
       (" 5", "Sand dunes"),
     ]
     #
     # ---------------------- BUTTONS
     #
     SubNB= []
     for mode, text in NB_SUB:
       c = Radiobutton(frameSub, text=text, indicatoron=0,
             variable=SubVal, value=mode, command=getSub)
       SubNB.append(c)
       c.pack()
   #
   #
   # ----------------------------------------------------------


SubWho can be a volatile list - change before calling buttons.


Simplicity itself.



Today is: 20090521
portions are from actual code
Python 2.5.2 and included Tkinter
Linux Slackware 10.2  (same source runs on Win XP PRO)

Steve



More information about the Python-list mailing list