473,473 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to link radio select with dialog in Tkinter

2 New Member
Hi evryone!!
I' m very new not only to Python and Tkinter but to programing.
I'm a bit stuck here and would be grateful for some help.
I have 3 radio select buttons(see below) which I want to link to a pmw dialog with (apply and cancel options ) i.e. when I press enable btn dialog pops up and asks to confirm the my choice and if apply is selected then run my enable script if cancel then close the dialog. the same with the other radio buttons,if disable is selected then the same dialog appears and ask again to apply or cancel.
So far I got the buttons working and I get the different values printed on the console and if I uncoment the second ""choice=v.block..."" this runs the script but at the moment from the "test" button. I don't need the buton and the console output instead I just want to be able to responce to the buttons via the dialog. I not sure if this makes any sence . this is some of my code so far.
thanks
Expand|Select|Wrap|Line Numbers
  1. def myDialog(w):
  2.     dialog = Pmw.Dialog(root, buttons=('Apply', 'Cancel'),defaultbutton='Apply',title='ConfirmSelection',command=block_firewall())
  3.     return  w
  4.  
  5. def block_firewall():
  6.     pipe_block = os.popen("./block-iptables", 'r')
  7.  
  8. def call():
  9.     choice = v.get()
  10.     #choice= v.block_firewall()
  11.     print '"Input %s "' % variant
  12.     #if choice
  13.  
  14. global v
  15. v = IntVar()
  16.  
  17. radiobutton = Radiobutton(frame,text= "Enable", variable=v, value="1")
  18. radiobutton.pack(side=TOP,anchor=W)
  19.  
  20. radiobutton = Radiobutton(frame,text= "Disable", variable=v, value="2")
  21. radiobutton.pack(side=TOP,anchor=W)
  22.  
  23. radiobutton = Radiobutton(frame,text= "Block All", variable=v, value="3")
  24. radiobutton.pack(side=TOP,anchor=W)
  25.  
  26. radiobutton.select()
  27.  
  28. test = Button(frame,text="Select",command=call)
  29. test.pack()
Apr 14 '07 #1
4 3366
bartonc
6,596 Recognized Expert Expert
Hi evryone!!
I' m very new not only to Python and Tkinter but to programing.
I'm a bit stuck here and would be grateful for some help.
I have 3 radio select buttons(see below) which I want to link to a pmw dialog with (apply and cancel options ) i.e. when I press enable btn dialog pops up and asks to confirm the my choice and if apply is selected then run my enable script if cancel then close the dialog. the same with the other radio buttons,if disable is selected then the same dialog appears and ask again to apply or cancel.
So far I got the buttons working and I get the different values printed on the console and if I uncoment the second ""choice=v.block..."" this runs the script but at the moment from the "test" button. I don't need the buton and the console output instead I just want to be able to responce to the buttons via the dialog. I not sure if this makes any sence . this is some of my code so far.
thanks
Expand|Select|Wrap|Line Numbers
  1. def myDialog(w):
  2.     dialog = Pmw.Dialog(root, buttons=('Apply', 'Cancel'),defaultbutton='Apply',title='ConfirmSelection',command=block_firewall())
  3.     return  w
  4.  
  5. def block_firewall():
  6.     pipe_block = os.popen("./block-iptables", 'r')
  7.  
  8. def call():
  9.     choice = v.get()
  10.     #choice= v.block_firewall()
  11.     print '"Input %s "' % variant
  12.     #if choice
  13.  
  14. global v
  15. v = IntVar()
  16.  
  17. radiobutton = Radiobutton(frame,text= "Enable", variable=v, value="1")
  18. radiobutton.pack(side=TOP,anchor=W)
  19.  
  20. radiobutton = Radiobutton(frame,text= "Disable", variable=v, value="2")
  21. radiobutton.pack(side=TOP,anchor=W)
  22.  
  23. radiobutton = Radiobutton(frame,text= "Block All", variable=v, value="3")
  24. radiobutton.pack(side=TOP,anchor=W)
  25.  
  26. radiobutton.select()
  27.  
  28. test = Button(frame,text="Select",command=call)
  29. test.pack()
I was going to say that you should have a look at this thread and post back, but looking at your code, we'll want to work on your structure a bit.
In the mean time, have a look around, read some of the Posting Guidelines so that I won't have to add CODE tags for you.

Thanks for joining the Python Forum on TheScripts.com.
Apr 14 '07 #2
bartonc
6,596 Recognized Expert Expert
I was going to say that you should have a look at this thread and post back, but looking at your code, we'll want to work on your structure a bit.
In the mean time, have a look around, read some of the Posting Guidelines so that I won't have to add CODE tags for you.

Thanks for joining the Python Forum on TheScripts.com.
Expand|Select|Wrap|Line Numbers
  1. from Tkinter import *
  2.  
  3. ## The trick is to SUB CLASS the widget that you want to add fuctionality to ##
  4. ## I don't have PMW, but the idea is the same: a Tkinter.Frame is just a blank ##
  5. ## frame until you subclass it an give it something to do ##  HAVE FUN
  6.  
  7. class MyFrame(Frame):
  8.     """A subclass of Tkinter.Frame that has some radio buttons that share a StringVar."""
  9.     def __init__(self, root, *args, **kwargs):
  10.         Frame.__init__(self, root, *args, **kwargs)
  11.  
  12.         # Create a variable to link the radio buttons
  13.         self.RadioButtonLink = RadioButtonLink = StringVar()
  14.         RadioButtonLink.set("On")  # or whatever you want the default to be
  15.  
  16.         # Create the radio buttons and arrange them on the frame
  17.         onRadio = Radiobutton(self, text="On", value="On", variable=RadioButtonLink)
  18.         onRadio.grid(row=0, column=0)
  19.         offRadio = Radiobutton(self, text="Off", value="Off", variable=RadioButtonLink)
  20.         offRadio.grid(row=0, column=1)
  21.         noneRadio = Radiobutton(self, text="None", value="None", variable=RadioButtonLink)
  22.         noneRadio.grid(row=0, column=2)
  23.  
  24.         # This is just so we have a way to make an event #
  25.         selectButton = Button(self, text='Select')
  26.         selectButton.grid(row=1, column=0, columnspan=3)
  27.         selectButton.bind("<Button-1>", self.OnButton)
  28.  
  29.     def OnButton(self, event):
  30.         """Print the value of the selected radio button."""
  31.         print self.RadioButtonLink.get()
  32.  
  33.  
  34. if __name__ == "__main__":
  35.     root = Tk()
  36.  
  37.     frame = MyFrame(root)
  38.     frame.pack()
  39.  
  40.  
  41.     root.mainloop()
  42.  
Apr 14 '07 #3
joseff
2 New Member
many thanks for the help guys , I got it working exactly as I wanted now tanks to you!!!
I hope one day I would be able to help others.
Apr 16 '07 #4
bartonc
6,596 Recognized Expert Expert
many thanks for the help guys , I got it working exactly as I wanted now tanks to you!!!
I hope one day I would be able to help others.
You are welcome. I LIKE your attitude.

Keep posting,
Barton
Apr 16 '07 #5

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

Similar topics

1
by: Thomas Nücker | last post by:
Hi! I am creating a dialog-box within my application, using tkinter. The problem is the following: After the dialogbox is started, the main application window comes again to top and the...
2
by: Stewart Midwinter | last post by:
I would like to link the contents of three OptionMenu lists. When I select an item from the first list (call it continents), the contents of the 2nd list (call it countries) would update. And in...
1
by: Rick | last post by:
After being frustrated with this issue on several occasions I think I found the secret sauce for solving the issue after reading a few different messages about what others thought and trying a...
4
by: Wouter van Ooijen | last post by:
I have a tool in Python to which I want to add a small GUI. The tools currently runs everywhere PySerial is supported. I need a file-access dialog. What is the preffered way to to this? Is there a...
1
by: Michael Yanowitz | last post by:
Hello: Below I have included a stripped down version of the GUI I am working on. It contains 2 dialog boxes - one main and one settings. It has the following problems, probably all related, that...
14
by: Wouter | last post by:
Hi, I try to make the follow. I want that i can click on a text link and that then a link wil be copyed in a input form box (<input type="text" name="img_url" />). I have google-ed about how...
2
by: vajratkarviraj | last post by:
Hi all, I'm using Python 2.5.1 and TkInter. Hey here is the problem. Suppose I have 4 radio buttons (lets say values 1,2,3 and 4). They arranged in 2 columns (Each of the 2 columns has 2 radio...
2
by: nicstel | last post by:
When we run this piece of code, we are getting a following error. output error File "src/lib/parametric/gen_freeze/Tkinter.py", line 1558, in init AttributeError: 'module' object has no...
0
by: nicstel | last post by:
Hello. My script run fine within python but not in my program(SDS/2 wich is a software like Autocad). The problem is I got an error when the time comes to read the line14 to 19. (Source code come...
0
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
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 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.