Hy guys I am testing my script, but something weird happend with this script. When i was running the script with the command print at the end of the function calculation, i got a good result , this means that my script is well done, but whe i am using the command return i can not define a value by using my button execute and always this script is printing a result before the execution. The main idea is to select a option and after that to execute a conditional with fornulas inside.
thanks in advance #####by using return #----------------------------------------- from Tkinter import * # start of GUI Panel stuff import tkMessageBox from grail.data import pcf from grail.data import model from grail.dialogs import gselectprojectdialog from grail import const from grail import gsys from grail import messages import time import glob import string import time import sys import os import math import Pmw class notebook: # initialization. receives the master widget # reference and the notebook orientation def __init__(self, master, side=LEFT): self.active_fr = None self.count = 0 self.choice = IntVar(0) # allows the TOP and BOTTOM # radiobuttons' positioning. if side in (TOP, BOTTOM): self.side = LEFT else: self.side = TOP # creates notebook's frames structure self.rb_fr = Frame(master, borderwidth=2, relief=RIDGE) self.rb_fr.pack(side=side, fill=BOTH) self.screen_fr = Frame(master, borderwidth=2, relief=RIDGE) self.screen_fr.pack(fill=BOTH) # return a master frame reference for the external frames (screens) def __call__(self): return self.screen_fr # add a new frame (screen) to the (bottom/left of the) notebook def add_screen(self, fr, title): b = Radiobutton(self.rb_fr, text=title, indicatoron=0, \ variable=self.choice, value=self.count, \ command=lambda: self.display(fr)) b.pack(fill=BOTH, side=self.side) # ensures the first frame will be # the first selected/enabled if not self.active_fr: fr.pack(fill=BOTH, expand=1) self.active_fr = fr self.count += 1 # returns a reference to the newly created # radiobutton (allowing its configuration/destruction) return b # hides the former active frame and shows # another one, keeping its reference def display(self, fr): self.active_fr.forget() fr.pack(fill=BOTH, expand=1) self.active_fr = fr # END #================================================================================ def calculation(): global method_case #=================================================================== # METHOD CASE #=================================================================== method_case = r.get()# 0 Simple Best # 1 Simple cutoff # 2 Complex cutoff file 19 root.destroy() return if method_case == 0: print "es 0" if method_case == 1: print "es 1" if method_case == 2: print "es 2" ###------------------------------- root = Tk() root.title(" Project Office") root.geometry("450x400") n = notebook(root, LEFT) Pmw.initialise() button3 = Button(root,text="Accept",fg="red", command=calculation) button3.pack(side="top") button4 = Button(root,text="Cancel",fg="red", command=root.destroy) button4.pack(side="top") # uses the notebook's frame #==================================================================== # #=================================================================== f1 = Frame(n()) method =[('SIMPLE BEST BLOCK VALUE', 0), ('SIMPLE APPLIED CUTOFF', 1), ('COMPLEX APPLIED CUTOFF FILE 19', 2)] r = IntVar() r.set(0) for text, value in method: b = Radiobutton(f1, text=text,value=value, variable=r) b.pack(anchor=W) case.set(0) # keeps the reference to the radiobutton (optional) x1 = n.add_screen(f1, "Case Study") root.mainloop() # END #####by using print #----------------------------------------- from Tkinter import * # start of GUI Panel stuff import tkMessageBox from grail.data import pcf from grail.data import model from grail.dialogs import gselectprojectdialog from grail import const from grail import gsys from grail import messages import time import glob import string import time import sys import os import math import Pmw class notebook: # initialization. receives the master widget # reference and the notebook orientation def __init__(self, master, side=LEFT): self.active_fr = None self.count = 0 self.choice = IntVar(0) # allows the TOP and BOTTOM # radiobuttons' positioning. if side in (TOP, BOTTOM): self.side = LEFT else: self.side = TOP # creates notebook's frames structure self.rb_fr = Frame(master, borderwidth=2, relief=RIDGE) self.rb_fr.pack(side=side, fill=BOTH) self.screen_fr = Frame(master, borderwidth=2, relief=RIDGE) self.screen_fr.pack(fill=BOTH) # return a master frame reference for the external frames (screens) def __call__(self): return self.screen_fr # add a new frame (screen) to the (bottom/left of the) notebook def add_screen(self, fr, title): b = Radiobutton(self.rb_fr, text=title, indicatoron=0, \ variable=self.choice, value=self.count, \ command=lambda: self.display(fr)) b.pack(fill=BOTH, side=self.side) # ensures the first frame will be # the first selected/enabled if not self.active_fr: fr.pack(fill=BOTH, expand=1) self.active_fr = fr self.count += 1 # returns a reference to the newly created # radiobutton (allowing its configuration/destruction) return b # hides the former active frame and shows # another one, keeping its reference def display(self, fr): self.active_fr.forget() fr.pack(fill=BOTH, expand=1) self.active_fr = fr # END #================================================================================ def calculation(): global method_case #=================================================================== # METHOD CASE #=================================================================== method_case = r.get()# 0 Simple Best # 1 Simple cutoff # 2 Complex cutoff file 19 root.destroy() print method_case ###------------------------------- root = Tk() root.title(" Project Office") root.geometry("450x400") n = notebook(root, LEFT) Pmw.initialise() button3 = Button(root,text="Accept",fg="red", command=calculation) button3.pack(side="top") button4 = Button(root,text="Cancel",fg="red", command=root.destroy) button4.pack(side="top") # uses the notebook's frame #==================================================================== # #=================================================================== f1 = Frame(n()) method =[('SIMPLE BEST BLOCK VALUE', 0), ('SIMPLE APPLIED CUTOFF', 1), ('COMPLEX APPLIED CUTOFF FILE 19', 2)] r = IntVar() r.set(0) for text, value in method: b = Radiobutton(f1, text=text,value=value, variable=r) b.pack(anchor=W) case.set(0) # keeps the reference to the radiobutton (optional) x1 = n.add_screen(f1, "Case Study") root.mainloop() # END -- View this message in context: http://www.nabble.com/RADIOBUTTON-AND-BUTTON-tp18759173p18759173.html Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. _______________________________________________ Tkinter-discuss mailing list Tkinter-discuss@python.org http://mail.python.org/mailman/listinfo/tkinter-discuss