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? -
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)
-
5 1136 dwblas 626
Recognized Expert Contributor
Are you using Tkinter (which version-->python3.x or 2x) or are you using Wx, QT, etc.
dwblas 626
Recognized Expert Contributor
I'm not sure I understand your delima, but generally you would do something like this simple example - 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()
I am using python 2.7 and TKINTER
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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...
|
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...
|
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...
|
by: paulrajj |
last post by:
hi to all,
How to Enable a text field only on selecting a radio button using only getElementById..
| |
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...
|
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...
|
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 <input type="radio" name="Ptype" value="Edit"<cfif...
|
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,...
|
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...
|
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...
| |
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |