Not able hide frame while selecting default radio button

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Rashmi002
    New Member
    • Oct 2016
    • 5

    Not able hide frame while selecting default radio button

    Hii,

    There is one application where two radio buttons are available.i.e default and custom. If custom is selected then one panel will be visible which contain available drives list of not selected checkbox which are generated based on list but while i am doing such things it generate checkbox many time while i am selecting custom again and again.It must be generated only once.if i select default radio then panel should be not visible.

    How to make panel in tkinter or which widget will be used to hide and show checkbox?
    how to generate check button on window properly?

    Code:
    def drive_select(self):
    flag=0
    if self.drive_w.get()==2:
    flag=1
    oc_files = []
    root_dir = []
    for d in string.ascii_uppercase:
    if os.path.exists('%s:\' % d):
    root_dir.append('%s:\' % d)
    
        frame3=Frame(self)
        frame3.pack(fill=BOTH)
        for dr in sorted(root_dir):
            chk_drive = Checkbutton(frame3, text= dr, variable= self.drive_w)
            chk_drive.pack(side=RIGHT,padx=5,pady=55)
    else:
        "do something"
    self.drive_w = IntVar()
    self.drive_w.set(1) # Default value i.e. Default drive
    sscan =[("Default",1),("Custom",2)]
    
    for txt,val in sscan:
    radiobtn_scan = Radiobutton(frame2,text=txt,variable=self.drive_w,value=val,command=self.drive_select)
    radiobtn_scan.pack(side=LEFT, padx=5, pady=5)
  • dwblas
    Recognized Expert Contributor
    • May 2008
    • 626

    #2
    Are you using Tkinter (which version-->python3.x or 2x) or are you using Wx, QT, etc.

    Comment

    • dwblas
      Recognized Expert Contributor
      • May 2008
      • 626

      #3
      I'm not sure I understand your delima, but generally you would do something like this simple example
      Code:
      from functools import partial
      from Tkinter import *
      
      class CB:
          def __init__(self, master):
            master.geometry("290x250+5+10" )
            self.master = master
      
            self.create_checkbuttons()
            self.create_normal_frame()
            self.create_custom_frame()
            self.exit_button()
          
      
      ##-------------------------------------------------------------------
          def cb_handler(self, cb_number, event):
              """ zero is the first checkbutton and one is the 2nd
              """
              print cb_number
              if cb_number==0:  ## normal
                  self.nf.grid(row=0, column=2)
                  self.cf.grid_forget()
              else:                  ## custom
                  self.cf.grid(row=0, column=2)
                  self.nf.grid_forget()
      
              self.var_1.set(0)   ## uncheck the buttons
              self.var_2.set(0)
              
          ##-------------------------------------------------------------------
          def create_checkbuttons(self):
              """ each checkbutton will raise it's own frame
              """
              self.cb_frame=Frame(self.master)
      
              ## first checkbutton
              self.var_1 = IntVar()
              self.var_1.set(0)          ## off=default
              b = Checkbutton(self.cb_frame, text="Normal", \
                                  font=("courier", 10), variable=self.var_1)
              b.grid(row=0, column=0)
              b.bind ( "<Button-1>", partial(self.cb_handler, 0))  ##<--zero is normal
      
              ## second checkbutton
              self.var_2 = IntVar()
              self.var_2.set(0)          ## off=default
              b2 = Checkbutton(self.cb_frame, text="Custom", \
                                  font=("courier", 10), variable=self.var_2)
              b2.grid(row=1, column=0)
              b2.bind ( "<Button-1>", partial(self.cb_handler, 1))  ##<--one is custom
              self.cb_frame.grid(row=0, column=0)
              
          ##-------------------------------------------------------------------
          def create_custom_frame(self):
              self.cf=Frame(self.master)
              Label(self.cf, text="Custom", fg="blue",
                    height=10, width=10)).grid()
              
          ##-------------------------------------------------------------------
          def create_normal_frame(self):
              self.nf=Frame(self.master)
              Label(self.nf, text="Normal", fg="red",
                    height=10, width=10).grid()
              
          ##-------------------------------------------------------------------
          def exit_button(self):
            exit=  Button(self.master, text='CANCEL',
                         command=self.master.quit, bg='red', fg='white' )
            exit.grid(row=10, column=0, columnspan=2)
      
      ##======================================================================
      if __name__ == "__main__":
         root = Tk()
         xx=CB(root)
         root.mainloop()

      Comment

      • Rashmi002
        New Member
        • Oct 2016
        • 5

        #4
        I am using python 2.7 and TKINTER

        Comment

        • Rashmi002
          New Member
          • Oct 2016
          • 5

          #5



          Go to the link and see the bugs..

          Comment

          • dwblas
            Recognized Expert Contributor
            • May 2008
            • 626

            #6
            You won't find many on any forum who will click on a blind link. Note that if the program is too large to post it is also too large for a volunteer to wade through. Finally, post what testing you have already done so we can eliminate them.

            Comment

            Working...