By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
462,229 Members | 493 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 462,229 IT Pros & Developers. It's quick & easy.

How to link radio select with dialog in Tkinter

P: 2
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
Share this Question
Share on Google+
4 Replies

bartonc
Expert 5K+
P: 6,596
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
Expert 5K+
P: 6,596
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

P: 2
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
Expert 5K+
P: 6,596
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

Post your reply

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