473,503 Members | 1,694 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Not able hide frame while selecting default radio button

5 New Member
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?

Expand|Select|Wrap|Line Numbers
  1. def drive_select(self):
  2. flag=0
  3. if self.drive_w.get()==2:
  4. flag=1
  5. oc_files = []
  6. root_dir = []
  7. for d in string.ascii_uppercase:
  8. if os.path.exists('%s:\' % d):
  9. root_dir.append('%s:\' % d)
  10.  
  11.     frame3=Frame(self)
  12.     frame3.pack(fill=BOTH)
  13.     for dr in sorted(root_dir):
  14.         chk_drive = Checkbutton(frame3, text= dr, variable= self.drive_w)
  15.         chk_drive.pack(side=RIGHT,padx=5,pady=55)
  16. else:
  17.     "do something"
  18. self.drive_w = IntVar()
  19. self.drive_w.set(1) # Default value i.e. Default drive
  20. sscan =[("Default",1),("Custom",2)]
  21.  
  22. for txt,val in sscan:
  23. radiobtn_scan = Radiobutton(frame2,text=txt,variable=self.drive_w,value=val,command=self.drive_select)
  24. radiobtn_scan.pack(side=LEFT, padx=5, pady=5)
  25.  
Oct 7 '16 #1
5 1136
dwblas
626 Recognized Expert Contributor
Are you using Tkinter (which version-->python3.x or 2x) or are you using Wx, QT, etc.
Oct 7 '16 #2
dwblas
626 Recognized Expert Contributor
I'm not sure I understand your delima, but generally you would do something like this simple example
Expand|Select|Wrap|Line Numbers
  1. from functools import partial
  2. from Tkinter import *
  3.  
  4. class CB:
  5.     def __init__(self, master):
  6.       master.geometry("290x250+5+10" )
  7.       self.master = master
  8.  
  9.       self.create_checkbuttons()
  10.       self.create_normal_frame()
  11.       self.create_custom_frame()
  12.       self.exit_button()
  13.  
  14.  
  15. ##-------------------------------------------------------------------
  16.     def cb_handler(self, cb_number, event):
  17.         """ zero is the first checkbutton and one is the 2nd
  18.         """
  19.         print cb_number
  20.         if cb_number==0:  ## normal
  21.             self.nf.grid(row=0, column=2)
  22.             self.cf.grid_forget()
  23.         else:                  ## custom
  24.             self.cf.grid(row=0, column=2)
  25.             self.nf.grid_forget()
  26.  
  27.         self.var_1.set(0)   ## uncheck the buttons
  28.         self.var_2.set(0)
  29.  
  30.     ##-------------------------------------------------------------------
  31.     def create_checkbuttons(self):
  32.         """ each checkbutton will raise it's own frame
  33.         """
  34.         self.cb_frame=Frame(self.master)
  35.  
  36.         ## first checkbutton
  37.         self.var_1 = IntVar()
  38.         self.var_1.set(0)          ## off=default
  39.         b = Checkbutton(self.cb_frame, text="Normal", \
  40.                             font=("courier", 10), variable=self.var_1)
  41.         b.grid(row=0, column=0)
  42.         b.bind ( "<Button-1>", partial(self.cb_handler, 0))  ##<--zero is normal
  43.  
  44.         ## second checkbutton
  45.         self.var_2 = IntVar()
  46.         self.var_2.set(0)          ## off=default
  47.         b2 = Checkbutton(self.cb_frame, text="Custom", \
  48.                             font=("courier", 10), variable=self.var_2)
  49.         b2.grid(row=1, column=0)
  50.         b2.bind ( "<Button-1>", partial(self.cb_handler, 1))  ##<--one is custom
  51.         self.cb_frame.grid(row=0, column=0)
  52.  
  53.     ##-------------------------------------------------------------------
  54.     def create_custom_frame(self):
  55.         self.cf=Frame(self.master)
  56.         Label(self.cf, text="Custom", fg="blue",
  57.               height=10, width=10)).grid()
  58.  
  59.     ##-------------------------------------------------------------------
  60.     def create_normal_frame(self):
  61.         self.nf=Frame(self.master)
  62.         Label(self.nf, text="Normal", fg="red",
  63.               height=10, width=10).grid()
  64.  
  65.     ##-------------------------------------------------------------------
  66.     def exit_button(self):
  67.       exit=  Button(self.master, text='CANCEL',
  68.                    command=self.master.quit, bg='red', fg='white' )
  69.       exit.grid(row=10, column=0, columnspan=2)
  70.  
  71. ##======================================================================
  72. if __name__ == "__main__":
  73.    root = Tk()
  74.    xx=CB(root)
  75.    root.mainloop() 
Oct 7 '16 #3
Rashmi002
5 New Member
I am using python 2.7 and TKINTER
Oct 10 '16 #4
Rashmi002
5 New Member
https://www.dropbox.com/s/7be6vc148m...error.PNG?dl=0


Go to the link and see the bugs..
Oct 10 '16 #5
dwblas
626 Recognized Expert Contributor
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.
Oct 10 '16 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

7
548
by: steve | last post by:
Hi all If I use this code <% If Request.Item("col")="firstcoll" Then Response.Write "Checked"%> in .aspx page for example like that <input type="radio" name="col" value="firstcoll" <% If...
3
8732
by: steve | last post by:
Sorry if I have post this two times. Hi all What I'm trying to achieve is: I have a form with two radio buttons, if a visitors check radio button 2 and click submit in the next page radio...
2
2291
by: xazos79 | last post by:
Hi All, I've come across the problem of not being able to re-enable a radio button with javascript if its initial state has been disabled in the Page_Load() method of the code behind. Might i...
1
6040
by: ismailc | last post by:
Hi, I need help! I Would like to know of one can unselect a radio button. i know one can unselect a radio button by selecting another radio button. but what happens when there is only...
3
4641
paulrajj
by: paulrajj | last post by:
hi to all, How to Enable a text field only on selecting a radio button using only getElementById..
5
14411
by: Dan Boyce | last post by:
Hi Everyone. It may be simple, I dunno... I never had to do this before and for the life of me I can't find anything on the net so far. I have a radio button group (which I'll post after this...
8
2228
rush it
by: rush it | last post by:
Is it possible to have a checkbox validate a radio button? I have two radio buttons (Free Lunch and Reduced Lunch). If the user chooses either of these, the checkbox below (Please agree to the...
2
3546
by: taunt | last post by:
Hello I'm trying to make a sertain radio button the default. How would I get about doing this? Here is my coding so far: <td> Edit&nbsp;<input type="radio" name="Ptype" value="Edit"<cfif...
0
7202
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7086
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6991
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7462
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5014
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3167
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1512
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.