473,763 Members | 7,727 Online
Bytes | Software Development & Data Engineering Community
+ 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.bloc k..."" 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 3393
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.bloc k..."" 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
5904
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 dialogbox is covered by the window of the main application and must be "fetched" again via the taskbar to continue. Is there a way to "force" the dialogbox on top of all other windows? (I'm using MSWindows and Python22) The source of my dialogbox-class...
2
4637
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 turn the contents of the 3rd list (call it states would be updated by a change in the 2nd list. If anyone can share a recipe or some ideas, I'd be grateful! Here's some sample code that displays three OptionMenus, but doesn't update the list...
1
6946
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 combination of them all. What worked for me was the following: 1. Put a Break Point in MFC source file DLGDATA.CPP on line 338 which is: TRACE0("Warning: skipping non-radio button in group.\n"); (Copyright
4
1992
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 platform-independent file-access dialog available, or should I use the windows native version when running on windows (and how do I do that)? Wouter van Ooijen -- ------------------------------------
1
3598
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 I am hoping someone knows what I am doing wrong: 1) Pressing the Settings.. Button multiple times, brings up many instances of the Settings Panel. I just want it to bring up one. Is there an easy way to do that?
14
3276
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 i can make this but i cant find a explane how i can do this. I'm sure my javascript skills are the problem.... Is there here someone who can help me whit this ?
2
1712
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 buttons). I want to produce a specific action whenever I select a total of 2 radio buttons (and click on the "Submit" button), 1 from each column. Suppose say 1 and 3 are selected it should print 'a'. If 1 and 4, then print 'b' and similarly for radio...
2
1800
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 attribute 'argv' piece of code from Tkinter import *
0
3987
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 from Tkinter.py) class Tk(Misc, Wm): """Toplevel widget of Tk which represents mostly the main window of an appliation. It has an associated Tcl interpreter.""" _w = '.' def __init__(self, screenName=None, baseName=None,...
0
9997
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9937
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9822
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8821
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5270
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
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 we have to send another system
3
3522
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.