def build_heuristics_list(self): """ Construit la liste des heuristiques disponibles :return: IntVar - Identifiant de la liste des boutons """ # Label heuristic_label = Label(self, text="Choix de l'heuristique") heuristic_label.configure(font=font.Font(family=Config.FONT["main"], size=Config.SIZE["large"]), background=Config.COLOR["main-bg"], foreground=Config.COLOR["main-fg"]) heuristic_label.grid(sticky='w', padx=10) # Radio buttons x = IntVar(value=1) for index, text in enumerate(Menu.HEURISTICS): rdo = Radiobutton(self, text=text, variable=x, value=index + 1, tristatevalue=0) rdo.configure(font=font.Font(family=Config.FONT["main"], size=Config.SIZE["medium"]), background=Config.COLOR["main-bg"], foreground=Config.COLOR["main-fg"], activebackground=Config.COLOR["main-bg"], activeforeground=Config.COLOR["main-fg"], selectcolor=Config.COLOR["main-bg"]) rdo.grid(sticky='w', padx=20) return x
def get_filter(self, list_video=[], list_type=[]): if list_video: # Initialize Canvas # radio button if len(self.your_video.title) > 50: self.title_video = "Title: " + \ self.your_video.title[:50] + "..." else: self.title_video = "Title: " + self.your_video.title label_title = Label(self, text=self.title_video) label_title.grid(row=3, column=0, columnspan=3, padx=5) label_title.configure(background='#fff') label_save_as = Label(self, text="Save as") label_save_as.grid(row=4, column=1, sticky=W, padx=10) label_save_as.configure(background='#fff') self.choose = StringVar() for id, value in enumerate(sorted(list_type)): if id == 0: self.choose.set(value) R1 = Radiobutton(self, text=value, variable=self.choose, value=value, command=self.choose_save_as) R1.grid(row=5+id, column=1, sticky=W, padx=10) R1.configure(background='#fff') # menu dorpdown label_quality = Label(self, text="Quality") label_quality.grid(row=4, column=2, sticky=W) label_quality.configure(background='#fff') # list quality label_quality_select = Label(self) label_quality_select.grid(row=5, column=2, sticky=W, padx=10) label_quality_select.configure(background='#fff')
class Select_Py_Version(_Dialog): """ Select_Py_Version is a tkinter pop-up dialog used to select a python interpreter for use with Tk_Nosy. """ def body(self, master): dialogframe = Frame(master, width=300, height=300) dialogframe.pack() self.Label_1 = Label(dialogframe, text="Select Python Version") self.Label_1.pack() if self.dialogOptions: rbL = self.dialogOptions.get('rbL', ['No Options','No Options']) else: rbL = ['No Options', 'No Options'] self.RadioGroup1_StringVar = StringVar() self.RadioGroup1_StringVar.set(rbL[0]) self.RadioGroup1_StringVar_traceName = \ self.RadioGroup1_StringVar.trace_variable("w", self.RadioGroup1_StringVar_Callback) for rb in rbL: self.Radiobutton_1 = Radiobutton(dialogframe, text=rb, value=rb) self.Radiobutton_1.pack(anchor=W) self.Radiobutton_1.configure( variable=self.RadioGroup1_StringVar ) self.resizable(0, 0) # Linux may not respect this def RadioGroup1_StringVar_Callback(self, varName, index, mode): """When radio group selection changes, print message to CLI.""" print( "RadioGroup1_StringVar_Callback varName, index, mode", varName, index, mode ) print( " new StringVar value =", self.RadioGroup1_StringVar.get() ) def validate(self): """Validates and packages dialog selections prior to return to calling routine. set values in "self.result" dictionary for return """ self.result = {} # return a dictionary of results self.result["selection"] = self.RadioGroup1_StringVar.get() return 1 def apply(self): print( 'apply called')
class Select_Py_Version(_Dialog): """ Select_Py_Version is a tkinter pop-up dialog used to select a python interpreter for use with Tk_Nosy. """ def body(self, master): dialogframe = Frame(master, width=300, height=300) dialogframe.pack() self.Label_1 = Label(dialogframe, text="Select Python Version") self.Label_1.pack() if self.dialogOptions: rbL = self.dialogOptions.get('rbL', ['No Options', 'No Options']) else: rbL = ['No Options', 'No Options'] self.RadioGroup1_StringVar = StringVar() self.RadioGroup1_StringVar.set(rbL[0]) self.RadioGroup1_StringVar_traceName = \ self.RadioGroup1_StringVar.trace_variable("w", self.RadioGroup1_StringVar_Callback) for rb in rbL: self.Radiobutton_1 = Radiobutton(dialogframe, text=rb, value=rb) self.Radiobutton_1.pack(anchor=W) self.Radiobutton_1.configure(variable=self.RadioGroup1_StringVar) self.resizable(0, 0) # Linux may not respect this def RadioGroup1_StringVar_Callback(self, varName, index, mode): """When radio group selection changes, print message to CLI.""" print("RadioGroup1_StringVar_Callback varName, index, mode", varName, index, mode) print(" new StringVar value =", self.RadioGroup1_StringVar.get()) def validate(self): """Validates and packages dialog selections prior to return to calling routine. set values in "self.result" dictionary for return """ self.result = {} # return a dictionary of results self.result["selection"] = self.RadioGroup1_StringVar.get() return 1 def apply(self): print('apply called')
class contrast_color_picker(_Dialog): def body(self, master): dialogframe = Frame(master, width=584, height=321) self.dialogframe = dialogframe dialogframe.pack() self.RadioGroup_1_StringVar = StringVar() self.make_Canvas_1(self.dialogframe) # Canvas: at Main(2,2) self.make_Frame_1(self.dialogframe) # Frame: at Main(2,1) self.make_Label_1(self.dialogframe) # Label: at Main(2,3) self.make_Label_11( self.dialogframe) # Label: dark : at Main(3,4) self.make_Label_12( self.dialogframe) # Label: light : at Main(3,5) self.make_Label_6(self.dialogframe) # Label: at Main(2,6) self.make_RadioGroup_1( self.dialogframe ) # RadioGroup: Select Nominal Contrast Ratio : at Main(3,2) self.make_Scale_1(self.dialogframe) # Scale: at Main(2,4) self.make_Scale_2(self.dialogframe) # Scale: at Main(2,5) self.make_Button_1( self.Frame_1 ) # Button: Select Generic BG Color : at Frame_1(1,1) self.make_Button_2( self.Frame_1 ) # Button: Select Named BG Color : at Frame_1(2,1) self.make_Label_10( self.Frame_1 ) # Label: CR = Contrast Ratio : at Frame_1(10,1) self.make_Label_2( self.Frame_1) # Label: #ffffff : at Frame_1(4,1) self.make_Label_3( self.Frame_1) # Label: background color : at Frame_1(3,1) self.make_Label_4( self.Frame_1 ) # Label: contrasting foreground color : at Frame_1(6,1) self.make_Label_5( self.Frame_1) # Label: #000000 : at Frame_1(7,1) self.make_Label_7(self.Frame_1) # Label: at Frame_1(9,1) self.make_Label_8(self.Frame_1) # Label: at Frame_1(5,1) self.make_Label_9( self.Frame_1 ) # Label: click color chart to select : at Frame_1(8,1) self.make_Radiobutton_1( self.RadioGroup_1 ) # Radiobutton: AA CR=4.5:1 normal text : at RadioGroup_1(1,1) self.make_Radiobutton_2( self.RadioGroup_1 ) # Radiobutton: AA CR=3:1 large text : at RadioGroup_1(2,1) self.make_Radiobutton_3( self.RadioGroup_1 ) # Radiobutton: AAA CR=7:1 for normal text : at RadioGroup_1(3,1) self.make_Radiobutton_4( self.RadioGroup_1 ) # Radiobutton: AAA CR=4.5:1 for large text : at RadioGroup_1(4,1) self.dialogframe.columnconfigure(1, weight=1) self.RadioGroup_1_StringVar.set("2") self.RadioGroup_1_StringVar_traceName = self.RadioGroup_1_StringVar.trace_variable( "w", self.RadioGroup_1_StringVar_Callback) # >>>>>>insert any user code below this comment for section "top_of_init" self.ref_color_str = '#808080' # '#ffffff' # default ref_color_str is white self.contrast_color_str = '#000000' # default contrast_color_str is black self.Label_2.configure(text=self.ref_color_str, fg=self.contrast_color_str, bg=self.ref_color_str) self.ref_lum_p05 = self.get_lum_p05(self.ref_color_str) self.con_lum_p05 = self.get_lum_p05(self.contrast_color_str) self.CR = 21.0 self.CR_request = 4.5 self.crL = [4.5, 3.0, 7.0, 4.5] self.set_targ_lum_from_radiogroup() self.draw_canvas() self.ignore_slider = False def get_lum_p05(self, cstr): """Return luminance + 0.05 (used in contrast ratio calc.)""" (r, g, b) = hex_to_rgbfloat(cstr) lum_p05 = w3_luminance(r, g, b) + 0.05 return lum_p05 def set_slider_targ_lum(self): self.ignore_slider = True min_cr_val = 1.0 # ---------- set Scale_1 based on best contrast possible #if self.ref_lum_p05 > 0.229: # best contrast is for low luminosity max_cr_val = self.ref_lum_p05 / 0.05 #else: # max_cr_val = max(1.05/self.ref_lum_p05, self.CR_request) self.Scale_1.configure(tickinterval=0.1, from_=min_cr_val, to=max_cr_val, resolution=0.1, digits=3) self.Scale_1_StringVar.set(self.CR_request) # ---------- set Scale_2 based on lesser contrast possible #if self.ref_lum_p05 > 0.229: # IGNORE best contrast is for low luminosity max_cr_val = 1.05 / self.ref_lum_p05 #else: #max_cr_val = self.ref_lum_p05 / 0.05 self.Scale_2.configure(tickinterval=0.1, from_=min_cr_val, to=max_cr_val, resolution=0.1, digits=3) self.Scale_2_StringVar.set(self.CR_request) self.ignore_slider = False def set_targ_lum_from_radiogroup(self): i = int(self.RadioGroup_1_StringVar.get()) - 1 self.CR_request = self.crL[i] # calc required target luminance based on Radio Group Selection if self.ref_lum_p05 > 0.229: # best contrast is for low luminosity self.targ_lum = max(0.0, (self.ref_lum_p05 / self.CR_request) - 0.05) else: # best contrast is for high luminosity self.targ_lum = min(1.0, (self.CR_request * self.ref_lum_p05) - 0.05) self.set_slider_targ_lum() def draw_canvas(self): # clear canvas self.Canvas_1.delete("all") # paint canvas for i in range(N_CANVAS): for j in range(N_CANVAS): I = IMIN + i * DI Q = QMIN + j * DQ (r, g, b) = wiq_to_rgb(self.targ_lum, I, Q) cstr = rgbfloat_to_hex((r, g, b)) w = i * DX_CANVAS h = j * DX_CANVAS self.Canvas_1.create_rectangle( (w, h, w + DX_CANVAS, h + DX_CANVAS), outline=cstr, fill=cstr) # make sure that contrast label is set. self.set_contrast_color_label() def set_contrast_color_label(self): if self.ref_lum_p05 > self.con_lum_p05: self.CR = self.ref_lum_p05 / self.con_lum_p05 else: self.CR = self.con_lum_p05 / self.ref_lum_p05 msg = 'fg=%s, CR=%.1f' % (self.contrast_color_str, self.CR) self.Label_5.configure(text=msg, bg=self.ref_color_str, fg=self.contrast_color_str, width=len(msg) + 2) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Canvas_1" def make_Canvas_1(self, frame): """ Canvas: at Main(2,2)""" self.Canvas_1 = Canvas(frame, height="160", width="160") self.Canvas_1.grid(row=2, column=2, sticky="n") # >>>>>>insert any user code below this comment for section "make_Canvas_1" self.Canvas_1.config(bg='#ffffcc', height=CANVAS_SIZE, width=CANVAS_SIZE) self.Canvas_1.bind("<ButtonRelease-1>", self.Canvas_1_Click) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Frame_1" def make_Frame_1(self, frame): """ Frame: at Main(2,1)""" self.Frame_1 = Frame(frame, width="60", relief="flat", height="50", borderwidth="6") self.Frame_1.grid(row=2, column=1, rowspan="2") # >>>>>>insert any user code below this comment for section "make_Frame_1" # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Label_1" def make_Label_1(self, frame): """ Label: at Main(2,3)""" self.Label_1 = Label(frame, text="", width="2") self.Label_1.grid(row=2, column=3) # >>>>>>insert any user code below this comment for section "make_Label_1" # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Label_11" def make_Label_11(self, frame): """ Label: dark : at Main(3,4)""" self.Label_11 = Label(frame, text="dark", width="5") self.Label_11.grid(row=3, column=4, sticky="ne") # >>>>>>insert any user code below this comment for section "make_Label_11" # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Label_12" def make_Label_12(self, frame): """ Label: light : at Main(3,5)""" self.Label_12 = Label(frame, text="light", width="5") self.Label_12.grid(row=3, column=5, sticky="ne") # >>>>>>insert any user code below this comment for section "make_Label_12" # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Label_6" def make_Label_6(self, frame): """ Label: at Main(2,6)""" self.Label_6 = Label(frame, text="", width="2") self.Label_6.grid(row=2, column=6) # >>>>>>insert any user code below this comment for section "make_Label_6" # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_RadioGroup_1" def make_RadioGroup_1(self, frame): """ RadioGroup: Select Nominal Contrast Ratio : at Main(3,2)""" self.RadioGroup_1 = LabelFrame(frame, text="Select Nominal Contrast Ratio", width="60", height="50") self.RadioGroup_1.grid(row=3, column=2, sticky="new", columnspan="2") # >>>>>>insert any user code below this comment for section "make_RadioGroup_1" # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Scale_1" def make_Scale_1(self, frame): """ Scale: at Main(2,4)""" self.Scale_1 = Scale(frame, width="16", to="100", length="160", borderwidth="1", label="") self.Scale_1.grid(row=2, column=4, sticky="n") self.Scale_1_StringVar = StringVar() # >>>>>>insert any user code below this comment for section "make_Scale_1" self.Scale_1.configure(variable=self.Scale_1_StringVar) self.Scale_1_StringVar_traceName = self.Scale_1_StringVar.trace_variable( "w", self.Scale_1_StringVar_Callback) self.Scale_1.configure(length=CANVAS_SIZE) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Scale_2" def make_Scale_2(self, frame): """ Scale: at Main(2,5)""" self.Scale_2 = Scale(frame, to="100", width="16", length="160", borderwidth="1", label="") self.Scale_2.grid(row=2, column=5, sticky="n") self.Scale_2_StringVar = StringVar() # >>>>>>insert any user code below this comment for section "make_Scale_2" self.Scale_2.configure(variable=self.Scale_2_StringVar) self.Scale_2_StringVar_traceName = self.Scale_2_StringVar.trace_variable( "w", self.Scale_2_StringVar_Callback) self.Scale_2.configure(length=CANVAS_SIZE) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Button_1" def make_Button_1(self, frame): """ Button: Select Generic BG Color : at Frame_1(1,1)""" self.Button_1 = Button(frame, text="Select Generic BG Color", width="30") self.Button_1.grid(row=1, column=1, sticky="ew") # >>>>>>insert any user code below this comment for section "make_Button_1" self.Button_1.bind("<ButtonRelease-1>", self.Button_1_Click) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Button_2" def make_Button_2(self, frame): """ Button: Select Named BG Color : at Frame_1(2,1)""" self.Button_2 = Button(frame, text="Select Named BG Color", width="30") self.Button_2.grid(row=2, column=1, sticky="ew") # >>>>>>insert any user code below this comment for section "make_Button_2" self.Button_2.bind("<ButtonRelease-1>", self.Button_2_Click) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Label_10" def make_Label_10(self, frame): """ Label: CR = Contrast Ratio : at Frame_1(10,1)""" self.Label_10 = Label(frame, text="CR = Contrast Ratio", width="30") self.Label_10.grid(row=10, column=1) # >>>>>>insert any user code below this comment for section "make_Label_10" # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Label_2" def make_Label_2(self, frame): """ Label: #ffffff : at Frame_1(4,1)""" self.Label_2 = Label(frame, foreground="#000000", text="#ffffff", width="15", background="#ffffff", font="Times\ New\ Roman 16 bold roman") self.Label_2.grid(row=4, column=1, sticky="ew") # >>>>>>insert any user code below this comment for section "make_Label_2" # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Label_3" def make_Label_3(self, frame): """ Label: background color : at Frame_1(3,1)""" self.Label_3 = Label(frame, text="background color", width="15") self.Label_3.grid(row=3, column=1) # >>>>>>insert any user code below this comment for section "make_Label_3" # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Label_4" def make_Label_4(self, frame): """ Label: contrasting foreground color : at Frame_1(6,1)""" self.Label_4 = Label(frame, text="contrasting foreground color", width="25") self.Label_4.grid(row=6, column=1) # >>>>>>insert any user code below this comment for section "make_Label_4" # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Label_5" def make_Label_5(self, frame): """ Label: #000000 : at Frame_1(7,1)""" self.Label_5 = Label(frame, foreground="#000000", text="#000000", width="15", background="#ffffff", font="Times\ New\ Roman 16 bold roman") self.Label_5.grid(row=7, column=1, sticky="ew") # >>>>>>insert any user code below this comment for section "make_Label_5" # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Label_7" def make_Label_7(self, frame): """ Label: at Frame_1(9,1)""" self.Label_7 = Label(frame, text="", width="15") self.Label_7.grid(row=9, column=1) # >>>>>>insert any user code below this comment for section "make_Label_7" # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Label_8" def make_Label_8(self, frame): """ Label: at Frame_1(5,1)""" self.Label_8 = Label(frame, text="", width="15") self.Label_8.grid(row=5, column=1) # >>>>>>insert any user code below this comment for section "make_Label_8" # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Label_9" def make_Label_9(self, frame): """ Label: click color chart to select : at Frame_1(8,1)""" self.Label_9 = Label(frame, text="click color chart to select", width="30", font="Times\ New\ Roman 12 bold roman") self.Label_9.grid(row=8, column=1) # >>>>>>insert any user code below this comment for section "make_Label_9" # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Radiobutton_1" def make_Radiobutton_1(self, frame): """ Radiobutton: AA CR=4.5:1 normal text : at RadioGroup_1(1,1)""" self.Radiobutton_1 = Radiobutton(frame, text="AA CR=4.5:1 normal text", value="1", width="20", anchor="w", justify="left") self.Radiobutton_1.grid(row=1, column=1, sticky="w") # >>>>>>insert any user code below this comment for section "make_Radiobutton_1" self.Radiobutton_1.configure(variable=self.RadioGroup_1_StringVar) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Radiobutton_2" def make_Radiobutton_2(self, frame): """ Radiobutton: AA CR=3:1 large text : at RadioGroup_1(2,1)""" self.Radiobutton_2 = Radiobutton(frame, text="AA CR=3:1 large text", value="2", width="16", anchor="w", justify="left") self.Radiobutton_2.grid(row=2, column=1, sticky="w") # >>>>>>insert any user code below this comment for section "make_Radiobutton_2" self.Radiobutton_2.configure(variable=self.RadioGroup_1_StringVar) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Radiobutton_3" def make_Radiobutton_3(self, frame): """ Radiobutton: AAA CR=7:1 for normal text : at RadioGroup_1(3,1)""" self.Radiobutton_3 = Radiobutton(frame, text="AAA CR=7:1 for normal text", value="3", width="20", anchor="w", justify="left") self.Radiobutton_3.grid(row=3, column=1, sticky="w") # >>>>>>insert any user code below this comment for section "make_Radiobutton_3" self.Radiobutton_3.configure(variable=self.RadioGroup_1_StringVar) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Radiobutton_4" def make_Radiobutton_4(self, frame): """ Radiobutton: AAA CR=4.5:1 for large text : at RadioGroup_1(4,1)""" self.Radiobutton_4 = Radiobutton(frame, text="AAA CR=4.5:1 for large text", value="4", width="20", anchor="w", justify="left") self.Radiobutton_4.grid(row=4, column=1, sticky="w") # >>>>>>insert any user code below this comment for section "make_Radiobutton_4" self.Radiobutton_4.configure(variable=self.RadioGroup_1_StringVar) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "Canvas_1_Click" def Canvas_1_Click(self, event): #bind method for component ID=Canvas_1 """ Canvas: at Main(2,2)""" pass # >>>>>>insert any user code below this comment for section "Canvas_1_Click" # replace, delete, or comment-out the following #print( "executed method Canvas_1_Click" ) #print( "clicked in canvas at x,y =",event.x,event.y ) #w = int(self.Canvas_1.cget("width")) #h = int(self.Canvas_1.cget("height")) #self.Canvas_1.create_rectangle((2, 2, w+1, h+1), outline="blue") #self.Canvas_1.create_line(0, 0, w+2, h+2, fill="red") x = int(event.x) y = int(event.y) #print( "event x,y=",x,y ) item = self.Canvas_1.find_closest(event.x, event.y) # fill color of rectangle on canvas self.contrast_color_str = self.Canvas_1.itemcget(item, "fill") self.con_lum_p05 = self.get_lum_p05(self.contrast_color_str) self.set_contrast_color_label() #self.set_slider_targ_lum() #self.Canvas_1.create_text(x,y, text="NE", fill="green", anchor=NE) #self.Canvas_1.create_text(x,y, text="SW", fill="magenta", anchor=SW) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "Button_1_Click" def Button_1_Click(self, event): #bind method for component ID=Button_1 """ Button: Select Generic BG Color : at Frame_1(1,1)""" pass # >>>>>>insert any user code below this comment for section "Button_1_Click" # replace, delete, or comment-out the following #print( "executed method Button_1_Click" ) ctup, cstr = tkinter.colorchooser.askcolor(title='Selected Color') if cstr: #print( cstr ) lum_p05 = self.get_lum_p05(cstr) if lum_p05 > 0.229: fg = '#000000' else: fg = '#ffffff' msg = cstr self.Label_2.configure(text=msg, fg=fg, bg=cstr, width=len(msg) + 2) self.ref_color_str = cstr self.ref_lum_p05 = self.get_lum_p05(self.ref_color_str) self.set_targ_lum_from_radiogroup() self.draw_canvas() # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "Button_2_Click" def Button_2_Click(self, event): #bind method for component ID=Button_2 """ Button: Select Named BG Color : at Frame_1(2,1)""" pass # >>>>>>insert any user code below this comment for section "Button_2_Click" # replace, delete, or comment-out the following #print( "executed method Button_2_Click" ) dialog = named_color_picker(self.parent, title="Get Named Color") if dialog.result is not None: (_, lum_p05, _, _, _, _, cstr, name) = dialog.result["named_color"] if lum_p05 > 0.229: fg = '#000000' else: fg = '#ffffff' msg = name + ' ' + cstr self.Label_2.configure(text=msg, fg=fg, bg=cstr, width=len(msg) + 2) self.ref_color_str = cstr self.ref_lum_p05 = self.get_lum_p05(self.ref_color_str) self.set_targ_lum_from_radiogroup() self.draw_canvas() # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "Scale_1_StringVar_traceName" def Scale_1_StringVar_Callback(self, varName, index, mode): """ Scale: at Main(2,4)""" pass # >>>>>>insert any user code below this comment for section "Scale_1_StringVar_traceName" # replace, delete, or comment-out the following #print( "Scale_1_StringVar_Callback varName, index, mode",varName, index, mode ) #print( " new StringVar value =",self.Scale_1_StringVar.get() ) if self.ignore_slider: return CR = float(self.Scale_1_StringVar.get()) #if self.ref_lum_p05 > 0.229: # best contrast is for low luminosity self.targ_lum = max(0.0, (self.ref_lum_p05 / CR) - 0.05) #else: # best contrast is for high luminosity # self.targ_lum = min(1.0, (CR * self.ref_lum_p05)-0.05 ) self.draw_canvas() # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "Scale_2_StringVar_traceName" def Scale_2_StringVar_Callback(self, varName, index, mode): """ Scale: at Main(2,5)""" pass # >>>>>>insert any user code below this comment for section "Scale_2_StringVar_traceName" # replace, delete, or comment-out the following #print( "Scale_2_StringVar_Callback varName, index, mode",varName, index, mode ) #print( " new StringVar value =",self.Scale_2_StringVar.get() ) if self.ignore_slider: return CR = float(self.Scale_2_StringVar.get()) #if self.ref_lum_p05 > 0.229: # IGNORE best contrast is for low luminosity # self.targ_lum = max(0.0, (self.ref_lum_p05 / CR)-0.05 ) #else: # IGNORE best contrast is for high luminosity self.targ_lum = min(1.0, (CR * self.ref_lum_p05) - 0.05) self.draw_canvas() # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "RadioGroup_1_StringVar_traceName" def RadioGroup_1_StringVar_Callback(self, varName, index, mode): """ RadioGroup: Select Nominal Contrast Ratio : at Main(3,2)""" pass # >>>>>>insert any user code below this comment for section "RadioGroup_1_StringVar_traceName" # replace, delete, or comment-out the following #print( "RadioGroup_1_StringVar_Callback varName, index, mode",varName, index, mode ) #print( " new StringVar value =",self.RadioGroup_1_StringVar.get() ) self.set_targ_lum_from_radiogroup() self.draw_canvas() # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "dialog_validate" def validate(self): self.result = {} # return a dictionary of results self.result["Scale_1"] = self.Scale_1_StringVar.get() self.result["Scale_2"] = self.Scale_2_StringVar.get() self.result["RadioGroup_1"] = self.RadioGroup_1_StringVar.get() # >>>>>>insert any user code below this comment for section "dialog_validate" # set values in "self.result" dictionary for return # for example... # self.result["age"] = self.Entry_2_StringVar.get() self.result = {} # reinitialize return a dictionary of results self.result["bg_color_str"] = self.ref_color_str self.result["fg_color_str"] = self.contrast_color_str self.result["contrast_ratio"] = self.CR return 1 # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "end" def apply(self): pass
class fg_bg_color_picker(_Dialog): def body(self, master): dialogframe = Frame(master, width=536, height=225) self.dialogframe = dialogframe dialogframe.pack() self.RadioGroup_1_StringVar = StringVar() self.make_LabelFrame_1( self.dialogframe) # LabelFrame: Colors : at Main(5,1) self.make_Label_1( self.dialogframe ) # Label: Left Click Background : at Main(2,1) self.make_Label_2( self.dialogframe ) # Label: Right Click Foreground : at Main(3,1) self.make_Label_3( self.dialogframe ) # Label: Luminance and Contrast Ratio shown above : at Main(4,1) self.make_RadioGroup_1( self.dialogframe) # RadioGroup: Sort By: : at Main(1,1) self.make_Radiobutton_1( self.RadioGroup_1) # Radiobutton: HSV hue : at RadioGroup_1(1,1) self.make_Radiobutton_2( self.RadioGroup_1 ) # Radiobutton: W3 Luminance : at RadioGroup_1(1,2) self.make_Radiobutton_3( self.RadioGroup_1 ) # Radiobutton: HEX String : at RadioGroup_1(1,3) self.make_Radiobutton_4( self.RadioGroup_1 ) # Radiobutton: Color Name : at RadioGroup_1(1,4) self.RadioGroup_1_StringVar.set("2") self.RadioGroup_1_StringVar_traceName = self.RadioGroup_1_StringVar.trace_variable( "w", self.RadioGroup_1_StringVar_Callback) # >>>>>>insert any user code below this comment for section "top_of_init" self.labelD = {} # index=(row,col): value=Label object row = 0 col = 0 for (lum, lum_p05, h, r, g, b, cstr, name) in lum_sorted_colorL: lab = Label(self.LabelFrame_1, text=" ", width="3", padx=0, pady=0, font=("times", "6", "normal")) lab.grid(row=row, column=col) self.labelD[(row, col)] = lab lab.configure(background=cstr, relief="raised") lab.bind("<Enter>", self.label_enter) lab.bind("<Leave>", self.label_leave) lab.bind("<ButtonRelease-1>", self.ColorPickLabel_LeftClick) lab.bind("<ButtonRelease-3>", self.ColorPickLabel_RightClick) col += 1 if col >= COL_COUNT: col = 0 row += 1 self.tw = None self.bg_selectionT = lum_sorted_colorL[-1] # set selection to white self.fg_selectionT = lum_sorted_colorL[0] # set selection to black self.bg_label = None self.fg_label = None def get_info_for_row_col(self, row, col): lab = self.labelD[(row, col)] val = self.RadioGroup_1_StringVar.get() if val == "1": L = h_sorted_colorL elif val == "2": L = lum_sorted_colorL elif val == "3": L = cstr_sorted_colorL elif val == "4": L = name_sorted_colorL i = col + row * COL_COUNT (lum, lum_p05, h, r, g, b, cstr, name) = L[i] return (lum, lum_p05, h, r, g, b, cstr, name) def unhighlight_label(self, label): if label is not None: label.configure(relief='raised', text=' ') def highlight_label(self, label, text=" X"): if label is not None: text = '<%s>' % text.strip() label.configure(relief='sunken', text=text) info = label.grid_info() row = int(info["row"]) col = int(info["column"]) (lumbg, lum_p05bg, hbg, rbg, gbg, bbg, cstrbg, namebg) = self.get_info_for_row_col(row, col) if lum_p05bg > 0.229: # gives Contrast Ratio of 4.5 or better with best of white or black label.configure(fg='#000000') else: label.configure(fg='#ffffff') def ColorPickLabel_RightClick(self, event): """Pick the Foreground color.""" self.unhighlight_label(self.fg_label) self.fg_label = event.widget self.highlight_label(self.fg_label, text=" F") info = event.widget.grid_info() row = int(info["row"]) col = int(info["column"]) #print((info["row"], info["column"])) (lumfg, lum_p05fg, hfg, rfg, gfg, bfg, cstrfg, namefg) = self.get_info_for_row_col(row, col) self.fg_selectionT = (lumfg, lum_p05fg, hfg, rfg, gfg, bfg, cstrfg, namefg) (lumbg, lum_p05bg, _, _, _, _, cstrbg, namebg) = self.bg_selectionT if lum_p05fg > lum_p05bg: CR = lum_p05fg / lum_p05bg else: CR = lum_p05bg / lum_p05fg text = 'Foreground: ' + namefg + " " + cstrfg.upper( ) + " lum=%.3f," % lumfg + " CR=%.2f" % CR self.Label_2.configure(fg=self.fg_selectionT[-2]) self.Label_2.configure(background=self.bg_selectionT[-2], text=text) def ColorPickLabel_LeftClick(self, event): """Pick the Background color""" self.unhighlight_label(self.bg_label) self.bg_label = event.widget self.highlight_label(self.bg_label, text=" B") # show selection info = event.widget.grid_info() row = int(info["row"]) col = int(info["column"]) #print((info["row"], info["column"])) (lumbg, lum_p05bg, hbg, rbg, gbg, bbg, cstrbg, namebg) = self.get_info_for_row_col(row, col) self.bg_selectionT = (lumbg, lum_p05bg, hbg, rbg, gbg, bbg, cstrbg, namebg) if lum_p05bg > 0.229: # gives Contrast Ratio of 4.5 or better with best of white or black local_fg_selectionT = lum_sorted_colorL[0] # black msg = ' (w black)' else: local_fg_selectionT = lum_sorted_colorL[-1] # white msg = ' (w white)' (lumfg, lum_p05fg, hfg, rfg, gfg, bfg, cstrfg, namefg) = local_fg_selectionT if self.fg_label is None: self.fg_selectionT = local_fg_selectionT if lum_p05fg > lum_p05bg: CR = lum_p05fg / lum_p05bg else: CR = lum_p05bg / lum_p05fg text = 'Background: ' + namebg + " " + cstrbg.upper( ) + " lum=%.3f," % lumbg + " CR=%.2f" % CR + msg self.Label_1.configure(fg=local_fg_selectionT[-2]) self.Label_1.configure(background=cstrbg, text=text) # local foreground may not be global foreground (lumfg, lum_p05fg, hfg, rfg, gfg, bfg, cstrfg, namefg) = self.fg_selectionT if lum_p05fg > lum_p05bg: CR = lum_p05fg / lum_p05bg else: CR = lum_p05bg / lum_p05fg text = 'Foreground: ' + namefg + " " + cstrfg.upper( ) + " lum=%.3f," % lumfg + " CR=%.2f" % CR self.Label_2.configure(fg=self.fg_selectionT[-2]) self.Label_2.configure(background=self.bg_selectionT[-2], text=text) def label_enter(self, event=None): if event is None: return info = event.widget.grid_info() row = int(info["row"]) col = int(info["column"]) #print((info["row"], info["column"])) (lum, lum_p05, h, r, g, b, cstr, name) = self.get_info_for_row_col(row, col) x = y = 0 try: x_y_cx_cy = event.widget.bbox("insert") except: x_y_cx_cy = None if x_y_cx_cy is not None: x, y, cx, cy = event.widget.bbox("insert") x += event.widget.winfo_rootx() + 40 y += event.widget.winfo_rooty() - 24 # creates a toplevel window self.tw = Toplevel(event.widget) # Leaves only the label and removes the app window self.tw.wm_overrideredirect(True) self.tw.wm_geometry("+%d+%d" % (x, y)) label = Label(self.tw, text=name, justify='left', background='#ffffff', relief='solid', borderwidth=1, font=("times", "12", "normal")) label.pack(ipadx=1) def label_leave(self, event=None): if self.tw: self.tw.destroy() # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_LabelFrame_1" def make_LabelFrame_1(self, frame): """ LabelFrame: Colors : at Main(5,1)""" self.LabelFrame_1 = LabelFrame(frame, text="Colors", width="60", height="50") self.LabelFrame_1.grid(row=5, column=1) # >>>>>>insert any user code below this comment for section "make_LabelFrame_1" # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Label_1" def make_Label_1(self, frame): """ Label: Left Click Background : at Main(2,1)""" self.Label_1 = Label(frame, text="Left Click Background", width="30", font="Times\ New\ Roman 18 bold roman") self.Label_1.grid(row=2, column=1, sticky="ew") # >>>>>>insert any user code below this comment for section "make_Label_1" # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Label_2" def make_Label_2(self, frame): """ Label: Right Click Foreground : at Main(3,1)""" self.Label_2 = Label(frame, text="Right Click Foreground", width="30", font="Times\ New\ Roman 18 bold roman") self.Label_2.grid(row=3, column=1, sticky="ew") # >>>>>>insert any user code below this comment for section "make_Label_2" # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Label_3" def make_Label_3(self, frame): """ Label: Luminance and Contrast Ratio shown above : at Main(4,1)""" self.Label_3 = Label(frame, text="Luminance and Contrast Ratio shown above", width="45") self.Label_3.grid(row=4, column=1, sticky="e") # >>>>>>insert any user code below this comment for section "make_Label_3" # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_RadioGroup_1" def make_RadioGroup_1(self, frame): """ RadioGroup: Sort By: : at Main(1,1)""" self.RadioGroup_1 = LabelFrame(frame, text="Sort By:", width="60", height="50") self.RadioGroup_1.grid(row=1, column=1) # >>>>>>insert any user code below this comment for section "make_RadioGroup_1" # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Radiobutton_1" def make_Radiobutton_1(self, frame): """ Radiobutton: HSV hue : at RadioGroup_1(1,1)""" self.Radiobutton_1 = Radiobutton(frame, text="HSV hue", value="1", width="15") self.Radiobutton_1.grid(row=1, column=1) # >>>>>>insert any user code below this comment for section "make_Radiobutton_1" self.Radiobutton_1.configure(variable=self.RadioGroup_1_StringVar) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Radiobutton_2" def make_Radiobutton_2(self, frame): """ Radiobutton: W3 Luminance : at RadioGroup_1(1,2)""" self.Radiobutton_2 = Radiobutton(frame, text="W3 Luminance", value="2", width="15") self.Radiobutton_2.grid(row=1, column=2) # >>>>>>insert any user code below this comment for section "make_Radiobutton_2" self.Radiobutton_2.configure(variable=self.RadioGroup_1_StringVar) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Radiobutton_3" def make_Radiobutton_3(self, frame): """ Radiobutton: HEX String : at RadioGroup_1(1,3)""" self.Radiobutton_3 = Radiobutton(frame, text="HEX String", value="3", width="15") self.Radiobutton_3.grid(row=1, column=3) # >>>>>>insert any user code below this comment for section "make_Radiobutton_3" self.Radiobutton_3.configure(variable=self.RadioGroup_1_StringVar) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Radiobutton_4" def make_Radiobutton_4(self, frame): """ Radiobutton: Color Name : at RadioGroup_1(1,4)""" self.Radiobutton_4 = Radiobutton(frame, text="Color Name", value="4", width="15") self.Radiobutton_4.grid(row=1, column=4) # >>>>>>insert any user code below this comment for section "make_Radiobutton_4" self.Radiobutton_4.configure(variable=self.RadioGroup_1_StringVar) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "RadioGroup_1_StringVar_traceName" def RadioGroup_1_StringVar_Callback(self, varName, index, mode): """ RadioGroup: Sort By: : at Main(1,1)""" pass # >>>>>>insert any user code below this comment for section "RadioGroup_1_StringVar_traceName" # replace, delete, or comment-out the following #print( "RadioGroup_1_StringVar_Callback varName, index, mode",varName, index, mode ) #print( " new StringVar value =",self.RadioGroup_1_StringVar.get() ) # handle label highlights self.unhighlight_label(self.fg_label) self.fg_label = None self.unhighlight_label(self.bg_label) self.bg_label = None # show resorting val = self.RadioGroup_1_StringVar.get() if val == "1": L = h_sorted_colorL elif val == "2": L = lum_sorted_colorL elif val == "3": L = cstr_sorted_colorL elif val == "4": L = name_sorted_colorL row = 0 col = 0 for (lum, lum_p05, h, r, g, b, cstr, name) in L: lab = self.labelD[(row, col)] lab.configure(background=cstr) if self.bg_selectionT[-1] == name: self.highlight_label(lab, text=" B") self.bg_label = lab if self.fg_selectionT[-1] == name: self.highlight_label(lab, text=" F") self.fg_label = lab col += 1 if col >= COL_COUNT: col = 0 row += 1 # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "dialog_validate" def validate(self): self.result = {} # return a dictionary of results self.result["RadioGroup_1"] = self.RadioGroup_1_StringVar.get() # >>>>>>insert any user code below this comment for section "dialog_validate" # set values in "self.result" dictionary for return # for example... # self.result["age"] = self.Entry_2_StringVar.get() self.result["bg_color"] = self.bg_selectionT self.result["fg_color"] = self.fg_selectionT return 1 # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "end" def apply(self): #print( 'apply called' ) pass
lbl_msj["text"] = "Has elegido: Femenino" # ------------------------- Creacion de widgets ------------------------------------ lbl_genero = Label(root, text="Género:", justify="left") lbl_genero.config(bg="White", font=("Century Schoolbook", 14, "bold italic")) lbl_msj = Label(root, text="", justify="center", bg="White") lbl_msj.config(fg="dark blue", font=("Century Schoolbook", 10, "bold italic")) rdBtn_masculino = Radiobutton(root, text="Masculino", variable=opcion, value=1, command=get_genero) rdBtn_masculino.configure(bg="White", font=("Century Schoolbook", 12, "bold italic")) rdBtn_femenino = Radiobutton(root, text="Femenino", variable=opcion, value=2, command=get_genero) rdBtn_femenino.configure(bg="White", font=("Century Schoolbook", 12, "bold italic")) lbl_genero.pack(padx=15, pady=10) rdBtn_masculino.pack(padx=15, pady=5) rdBtn_femenino.pack(padx=15, pady=5) lbl_msj.pack(side="bottom", padx=15, pady=15) root.config(bg="White")
class _get_value_v2(_Dialog): def body(self, master): dialogframe = Frame(master, width=426, height=213) self.dialogframe = dialogframe dialogframe.pack() self.RadioGroup_1_StringVar = StringVar() self.make_Entry_1(self.dialogframe) # Entry: at Main(3,2) self.make_Label_1( self.dialogframe) # Label: Input XXX Value : at Main(1,1) self.make_Label_2( self.dialogframe) # Label: definition : at Main(2,1) self.make_Label_3(self.dialogframe) # Label: XXX= : at Main(3,1) self.make_RadioGroup_1( self.dialogframe) # RadioGroup: XXX= : at Main(4,1) self.make_Radiobutton_1( self.RadioGroup_1) # Radiobutton: True : at RadioGroup_1(2,1) self.make_Radiobutton_2( self.RadioGroup_1) # Radiobutton: False : at RadioGroup_1(3,1) self.RadioGroup_1_StringVar.set("1") self.RadioGroup_1_StringVar_traceName = self.RadioGroup_1_StringVar.trace_variable( "w", self.RadioGroup_1_StringVar_Callback) # >>>>>>insert any user code below this comment for section "top_of_init" if type(False) == self.dialogOptions['val_type']: self.Label_3.grid_remove() self.Entry_1.grid_remove() value = self.dialogOptions.get('value', True) if value: self.RadioGroup_1_StringVar.set("1") else: self.RadioGroup_1_StringVar.set("2") else: self.RadioGroup_1.grid_remove() self.Entry_1.focus_set() self.Entry_1.select_range(0, END) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Entry_1" def make_Entry_1(self, frame): """ Entry: at Main(3,2)""" self.Entry_1 = Entry(frame, width="30") self.Entry_1.grid(row=3, column=2, sticky="w", columnspan="1") self.Entry_1_StringVar = StringVar() # >>>>>>insert any user code below this comment for section "make_Entry_1" value = self.dialogOptions.get('value', '') self.Entry_1_StringVar.set(value) self.Entry_1.configure(textvariable=self.Entry_1_StringVar) self.Entry_1_StringVar_traceName = self.Entry_1_StringVar.trace_variable( "w", self.Entry_1_StringVar_Callback) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Label_1" def make_Label_1(self, frame): """ Label: Input XXX Value : at Main(1,1)""" self.Label_1 = Label(frame, text="Input XXX Value", width="60") self.Label_1.grid(row=1, column=1, columnspan="2") # >>>>>>insert any user code below this comment for section "make_Label_1" name = self.dialogOptions.get('label', '') if not name: name = self.dialogOptions.get('name', '') self.Label_1.configure(text='Input: ' + name) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Label_2" def make_Label_2(self, frame): """ Label: definition : at Main(2,1)""" self.Label_2 = Label(frame, text="definition", width="60", height="4") self.Label_2.grid(row=2, column=1, columnspan="2") # >>>>>>insert any user code below this comment for section "make_Label_2" desc = self.dialogOptions.get('desc', '') self.Label_2.configure(text=desc, wraplength=400) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Label_3" def make_Label_3(self, frame): """ Label: XXX= : at Main(3,1)""" self.Label_3 = Label(frame, text="XXX=", width="20", anchor="e") self.Label_3.grid(row=3, column=1, sticky="e") # >>>>>>insert any user code below this comment for section "make_Label_3" name = self.dialogOptions.get('name', '') self.Label_3.configure(text=name + '=') # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_RadioGroup_1" def make_RadioGroup_1(self, frame): """ RadioGroup: XXX= : at Main(4,1)""" self.RadioGroup_1 = LabelFrame(frame, width="60", height="50", text="XXX=") self.RadioGroup_1.grid(row=4, column=1, columnspan="2") # >>>>>>insert any user code below this comment for section "make_RadioGroup_1" name = self.dialogOptions.get('label', '') if not name: name = self.dialogOptions.get('name', '') self.RadioGroup_1.configure(text='Input: ' + name) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Radiobutton_1" def make_Radiobutton_1(self, frame): """ Radiobutton: True : at RadioGroup_1(2,1)""" self.Radiobutton_1 = Radiobutton(frame, value="1", text="True", width="15", anchor="w") self.Radiobutton_1.grid(row=2, column=1) # >>>>>>insert any user code below this comment for section "make_Radiobutton_1" self.Radiobutton_1.configure(variable=self.RadioGroup_1_StringVar) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Radiobutton_2" def make_Radiobutton_2(self, frame): """ Radiobutton: False : at RadioGroup_1(3,1)""" self.Radiobutton_2 = Radiobutton(frame, value="2", text="False", width="15", anchor="w") self.Radiobutton_2.grid(row=3, column=1) # >>>>>>insert any user code below this comment for section "make_Radiobutton_2" self.Radiobutton_2.configure(variable=self.RadioGroup_1_StringVar) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "Entry_1_StringVar_traceName" def Entry_1_StringVar_Callback(self, varName, index, mode): """ Entry: at Main(3,2)""" pass # >>>>>>insert any user code below this comment for section "Entry_1_StringVar_traceName" # replace, delete, or comment-out the following #print( "Entry_1_StringVar_Callback varName, index, mode",varName, index, mode ) #print( " new StringVar value =",self.Entry_1_StringVar.get() ) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "RadioGroup_1_StringVar_traceName" def RadioGroup_1_StringVar_Callback(self, varName, index, mode): """ RadioGroup: XXX= : at Main(4,1)""" pass # >>>>>>insert any user code below this comment for section "RadioGroup_1_StringVar_traceName" # replace, delete, or comment-out the following #print( "RadioGroup_1_StringVar_Callback varName, index, mode",varName, index, mode ) #print( " new StringVar value =",self.RadioGroup_1_StringVar.get() ) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "standard_message_dialogs" # standard message dialogs... showinfo, showwarning, showerror def ShowInfo(self, title='Title', message='your message here.'): tkinter.messagebox.showinfo(title, message) return def ShowWarning(self, title='Title', message='your message here.'): tkinter.messagebox.showwarning(title, message) return def ShowError(self, title='Title', message='your message here.'): tkinter.messagebox.showerror(title, message) return # standard question dialogs... askquestion, askokcancel, askyesno, or askretrycancel # return True for OK, Yes, Retry, False for Cancel or No def AskYesNo(self, title='Title', message='your question here.'): return tkinter.messagebox.askyesno(title, message) def AskOK_Cancel(self, title='Title', message='your question here.'): return tkinter.messagebox.askokcancel(title, message) def AskRetryCancel(self, title='Title', message='your question here.'): return tkinter.messagebox.askretrycancel(title, message) # return "yes" for Yes, "no" for No def AskQuestion(self, title='Title', message='your question here.'): return tkinter.messagebox.askquestion(title, message) # END of standard message dialogs # >>>>>>insert any user code below this comment for section "standard_message_dialogs" # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "dialog_validate" def validate(self): self.result = {} # return a dictionary of results #self.result["Entry_1"] = self.Entry_1_StringVar.get() #self.result["RadioGroup_1"] = self.RadioGroup_1_StringVar.get() # >>>>>>insert any user code below this comment for section "dialog_validate" value = self.Entry_1_StringVar.get() #print('Entered value=',value, type(value) ) if type(11.11) == self.dialogOptions['val_type']: try: value = eval(value) except: self.ShowError( title='Invalid Float', message='"%s" NOT recognized as float\nPlease Try Again.' % value) return 0 if is_float(value) or is_int( value): # accept an integer as a float value = floatCast(value) else: print(' Rejected float value=', value, type(value)) self.ShowError( title='Invalid Float', message='"%s" is NOT a float\nPlease Try Again.' % value) return 0 # if float violates clamp, issue an error name = self.dialogOptions.get('label', '') if not name: name = self.dialogOptions.get('name', '') if name in value_clampD: min_value, max_value = value_clampD[name] if value < min_value or value > max_value: # violates range self.ShowError( title='Invalid %s Value' % name, message='"%s" MUST be >=%g and <=%g\nPlease Try Again.' % (name, min_value, max_value)) return 0 elif type(123) == self.dialogOptions['val_type']: try: value = eval(value) except: self.ShowError( title='Invalid Integer', message='"%s" NOT recognized as integer\nPlease Try Again.' % value) return 0 if is_int(value): value = intCast(value) else: self.ShowError( title='Invalid Integer', message='"%s" is NOT a float\nPlease Try Again.' % value) return 0 elif type("string") == self.dialogOptions['val_type']: value = str(value) elif type(False) == self.dialogOptions['val_type']: value = self.RadioGroup_1_StringVar.get() == '1' #print('Returning Boolean Value =', value, type(value)) self.result["return_value"] = value #print('Dialog result =', self.result) return 1 """ # for testing, reinstate this code below def Button_1_Click(self, event): #click method for component ID=1 desc = 'radius of curvature just downstream of throat (Rdownstream / Rthrt) this could be a very long description and we would just need to wrap it.' value = False dialog = _get_value_v2(self.master, "Test Dialog", dialogOptions={'name':'Area Ratio', 'value':value, 'desc':desc, 'val_type':type(value)}) """ # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "end" def apply(self): pass
class _Hatch_GUI(object): """ create a Hatch object from hatch_supt and to then create a skeleton python project. """ def __init__(self, master): self.initComplete = 0 self.master = master self.x, self.y, self.w, self.h = -1, -1, -1, -1 # bind master to <Configure> in order to handle any resizing, etc. # postpone self.master.bind("<Configure>", self.Master_Configure) self.master.bind('<Enter>', self.bindConfigure) self.master.title("PyHatch GUI") self.master.resizable(0, 0) # Linux may not respect this dialogframe = Frame(master, width=810, height=630) dialogframe.pack() self.Shortdesc_Labelframe = LabelFrame( dialogframe, text="Short Description (1-liner)", height="90", width="718") self.Shortdesc_Labelframe.place(x=60, y=127) helv20 = tkinter.font.Font(family='Helvetica', size=20, weight='bold') self.Buildproject_Button = Button(dialogframe, text="Build Project", width="15", font=helv20) self.Buildproject_Button.place(x=492, y=10, width=263, height=68) self.Buildproject_Button.bind("<ButtonRelease-1>", self.Buildproject_Button_Click) self.Selectdir_Button = Button(dialogframe, text="<Select Directory>", width="15") self.Selectdir_Button.place(x=72, y=585, width=672, height=31) self.Selectdir_Button.bind("<ButtonRelease-1>", self.Selectdir_Button_Click) self.Author_Entry = Entry(dialogframe, width="15") self.Author_Entry.place(x=228, y=424, width=187, height=21) self.Author_Entry_StringVar = StringVar() self.Author_Entry.configure(textvariable=self.Author_Entry_StringVar) self.Author_Entry_StringVar.set("John Doe") self.Classname_Entry = Entry(dialogframe, width="15") self.Classname_Entry.place(x=192, y=73, width=165, height=21) self.Classname_Entry_StringVar = StringVar() self.Classname_Entry.configure( textvariable=self.Classname_Entry_StringVar) self.Classname_Entry_StringVar.set("MyClass") self.Copyright_Entry = Entry(dialogframe, width="15") self.Copyright_Entry.place(x=228, y=478, width=461, height=21) self.Copyright_Entry_StringVar = StringVar() self.Copyright_Entry.configure( textvariable=self.Copyright_Entry_StringVar) self.Copyright_Entry_StringVar.set("Copyright (c) 2013 John Doe") self.Email_Entry = Entry(dialogframe, relief="sunken", width="15") self.Email_Entry.place(x=228, y=505, width=458, height=21) self.Email_Entry_StringVar = StringVar() self.Email_Entry.configure(textvariable=self.Email_Entry_StringVar) self.Email_Entry_StringVar.set("*****@*****.**") self.GithubUserName_Entry = Entry(dialogframe, relief="sunken", width="15") self.GithubUserName_Entry.place(x=228, y=539, width=458, height=21) self.GithubUserName_Entry_StringVar = StringVar() self.GithubUserName_Entry.configure( textvariable=self.GithubUserName_Entry_StringVar) self.GithubUserName_Entry_StringVar.set("github_user_name") self.Funcname_Entry = Entry(dialogframe, width="15") self.Funcname_Entry.place(x=192, y=100, width=157, height=21) self.Funcname_Entry_StringVar = StringVar() self.Funcname_Entry.configure( textvariable=self.Funcname_Entry_StringVar) self.Funcname_Entry_StringVar.set("my_function") # License values should be correct format LICENSE_OPTIONS = tuple(sorted(CLASSIFIER_D.keys())) self.License_Entry_StringVar = StringVar() self.License_Entry = OptionMenu(dialogframe, self.License_Entry_StringVar, *LICENSE_OPTIONS) self.License_Entry.place(x=552, y=424, width=184, height=21) self.License_Entry_StringVar.set(LICENSE_OPTIONS[0]) self.Mainpyname_Entry = Entry(dialogframe, width="15") self.Mainpyname_Entry.place(x=168, y=37, width=196, height=21) self.Mainpyname_Entry_StringVar = StringVar() self.Mainpyname_Entry.configure( textvariable=self.Mainpyname_Entry_StringVar) self.Mainpyname_Entry_StringVar.set("main.py") self.Projname_Entry = Entry(dialogframe, width="15") self.Projname_Entry.place(x=168, y=10, width=194, height=21) self.Projname_Entry_StringVar = StringVar() self.Projname_Entry.configure( textvariable=self.Projname_Entry_StringVar) self.Projname_Entry_StringVar.set("MyProject") self.Shortdesc_Entry = Entry(dialogframe, width="15") self.Shortdesc_Entry.place(x=72, y=150, width=688, height=48) self.Shortdesc_Entry_StringVar = StringVar() self.Shortdesc_Entry.configure( textvariable=self.Shortdesc_Entry_StringVar) self.Shortdesc_Entry_StringVar.set("My project does this") # Status must be correct format self.Status_Entry_StringVar = StringVar() self.Status_Entry = OptionMenu(dialogframe, self.Status_Entry_StringVar, *DEV_STATUS_OPTIONS) self.Status_Entry.place(x=228, y=451, width=183, height=21) self.Status_Entry_StringVar.set(DEV_STATUS_OPTIONS[0]) self.Version_Entry = Entry(dialogframe, width="15") self.Version_Entry.place(x=552, y=451, width=184, height=21) self.Version_Entry_StringVar = StringVar() self.Version_Entry.configure(textvariable=self.Version_Entry_StringVar) self.Version_Entry_StringVar.set("0.1.1") self.Author_Label = Label(dialogframe, text="Author", width="15") self.Author_Label.place(x=96, y=424, width=112, height=22) self.Classname_Label = Label(dialogframe, text="Class Name", width="15") self.Classname_Label.place(x=60, y=73, width=112, height=22) self.Copyright_Label = Label(dialogframe, text="Copyright", width="15") self.Copyright_Label.place(x=96, y=478, width=113, height=23) self.Email_Label = Label(dialogframe, text="Email", width="15") self.Email_Label.place(x=96, y=505, width=113, height=23) self.GithubUserName_Label = Label(dialogframe, text="GithubUserName", width="15") self.GithubUserName_Label.place(x=96, y=539, width=113, height=23) self.Funcname_Label = Label(dialogframe, text="Function Name", width="15") self.Funcname_Label.place(x=60, y=100, width=112, height=22) self.License_Label = Label(dialogframe, text="License", width="15") self.License_Label.place(x=432, y=424, width=113, height=23) self.Longdesc_Label = Label(dialogframe, text="Paragraph Description", width="15") self.Longdesc_Label.place(x=216, y=220, width=376, height=22) self.Mainpyname_Label = Label(dialogframe, text="Main Python File", width="15") self.Mainpyname_Label.place(x=48, y=37, width=112, height=22) self.Projname_Label = Label(dialogframe, text="Project Name", width="15") self.Projname_Label.place(x=48, y=10, width=112, height=22) self.Selectdir_Label = Label( dialogframe, text="Select the Directory Below Which to Place Your Project", width="15") self.Selectdir_Label.place(x=156, y=567, width=536, height=24) self.Status_Label = Label(dialogframe, text="Status", width="15") self.Status_Label.place(x=96, y=451, width=114, height=24) self.Version_Label = Label(dialogframe, text="Version", width="15") self.Version_Label.place(x=432, y=451, width=113, height=23) self.Isclass_Radiobutton = Radiobutton(dialogframe, text="Class Project", value="Class Project", width="15", anchor=W) self.Isclass_Radiobutton.place(x=320, y=73, width=135, height=27) self.RadioGroup1_StringVar = StringVar() self.RadioGroup1_StringVar.set("Class Project") self.RadioGroup1_StringVar_traceName = \ self.RadioGroup1_StringVar.trace_variable("w", self.RadioGroup1_StringVar_Callback) self.Isclass_Radiobutton.configure(variable=self.RadioGroup1_StringVar) self.Isfunction_Radiobutton = Radiobutton(dialogframe, text="Function Project", value="Function Project", width="15", anchor=W) self.Isfunction_Radiobutton.place(x=320, y=100, width=135, height=27) self.Isfunction_Radiobutton.configure( variable=self.RadioGroup1_StringVar) lbframe = Frame(dialogframe) self.Text_1_frame = lbframe scrollbar = Scrollbar(lbframe, orient=VERTICAL) self.Text_1 = Text(lbframe, width="40", height="6", yscrollcommand=scrollbar.set) scrollbar.config(command=self.Text_1.yview) scrollbar.pack(side=RIGHT, fill=Y) self.Text_1.pack(side=LEFT, fill=BOTH, expand=1) self.Text_1_frame.place(x=72, y=250, width=665, height=160) # >>>>>>insert any user code below this comment for section "top_of_init" self.dirname = '<Select Directory>' self.Funcname_Entry.config(state=DISABLED) h = Hatch(projName='MyProject', mainDefinesClass='N') if h.author: self.Author_Entry_StringVar.set(h.author) if h.proj_license: self.License_Entry_StringVar.set(h.proj_license) if h.proj_copyright: self.Copyright_Entry_StringVar.set(h.proj_copyright) if h.email: self.Email_Entry_StringVar.set(h.email) if h.github_user_name: self.GithubUserName_Entry_StringVar.set(h.github_user_name) del h def build_result_dict(self): """Takes user inputs from GUI and builds a dictionary of results""" # pylint: disable=W0201 self.result = {} # return a dictionary of results self.result["author"] = self.Author_Entry_StringVar.get() self.result["status"] = self.Status_Entry_StringVar.get() self.result["proj_license"] = self.License_Entry_StringVar.get() self.result["version"] = self.Version_Entry_StringVar.get() self.result["proj_copyright"] = self.Copyright_Entry_StringVar.get() self.result["email"] = self.Email_Entry_StringVar.get() self.result[ "github_user_name"] = self.GithubUserName_Entry_StringVar.get() self.result["main_py_name"] = self.Mainpyname_Entry_StringVar.get() self.result["proj_name"] = self.Projname_Entry_StringVar.get() self.result["class_name"] = self.Classname_Entry_StringVar.get() self.result["func_name"] = self.Funcname_Entry_StringVar.get() self.result["short_desc"] = self.Shortdesc_Entry_StringVar.get() self.result["para_desc"] = self.Text_1.get(1.0, END) self.result["parent_dir"] = self.dirname if self.RadioGroup1_StringVar.get() == "Class Project": self.result["is_class_project"] = 'Y' else: self.result["is_class_project"] = 'N' def Buildproject_Button_Click(self, event): """When clicked, this method gathers all the user inputs and builds the project skeleton in the directory specified. """ # tkinter requires arguments, but I don't use them # pylint: disable=W0613 # >>>>>>insert any user code below this comment for section "compID=29" # replace, delete, or comment-out the following #print "executed method Buildproject_Button_Click" if not os.path.isdir(self.dirname): ShowError( title='Need Parent Directory', message= 'You need to choose a directory in which to place your project.' ) else: self.build_result_dict() # builds self.result dict r = self.result h = Hatch(projName=r["proj_name"], mainDefinesClass=r["is_class_project"], mainPyFileName=r["main_py_name"], mainClassName=r["class_name"], mainFunctionName=r["func_name"], author=r["author"], proj_copyright=r["proj_copyright"], proj_license=r["proj_license"], version=r["version"], email=r["email"], status=r["status"], github_user_name=r["github_user_name"], simpleDesc=r["short_desc"], longDesc=r["para_desc"]) call_result = h.save_project_below_this_dir(self.dirname) if call_result == 'Success': if AskYesNo(title='Exit Dialog', message='Do you want to leave this GUI?'): self.master.destroy() else: ShowWarning( title='Project Build Error', message='Project did NOT build properly.\n'+\ 'Warning Message = (%s)'%call_result) # return a string containing directory name def AskDirectory(self, title='Choose Directory', initialdir="."): """Simply wraps the tkinter function of the "same" name.""" dirname = tkinter.filedialog.askdirectory(parent=self.master, initialdir=initialdir, title=title) return dirname # <-- string def Selectdir_Button_Click(self, event): # I don't care what the exception is, if there's a problem, bail # Also, I want to redefine the dirname attribute here # pylint: disable=W0702, W0201 # tkinter requires arguments, but I don't use them # pylint: disable=W0613 """Selects the directory in which to build project.""" dirname = self.AskDirectory(title='Choose Directory For Nose Tests', initialdir='.') if dirname: try: dirname = os.path.abspath(dirname) except: self.dirname = '<Select Directory>' return # let Alarm force dir selection self.dirname = dirname self.Selectdir_Button.config(text=self.dirname) def RadioGroup1_StringVar_Callback(self, varName, index, mode): # tkinter requires arguments, but I don't use them # pylint: disable=W0613 """Responds to changes in RadioGroup1_StringVar.""" if self.RadioGroup1_StringVar.get() == "Class Project": self.Funcname_Entry.config(state=DISABLED) self.Classname_Entry.config(state=NORMAL) else: self.Classname_Entry.config(state=DISABLED) self.Funcname_Entry.config(state=NORMAL) # tk_happy generated code. DO NOT EDIT THE FOLLOWING. section "Master_Configure" def bindConfigure(self, event): """bindConfigure and Master_Configure help stabilize GUI""" # tkinter requires arguments, but I don't use them # pylint: disable=W0613 if not self.initComplete: self.master.bind("<Configure>", self.Master_Configure) self.initComplete = 1 def Master_Configure(self, event): """bindConfigure and Master_Configure help stabilize GUI""" # >>>>>>insert any user code below this comment for section "Master_Configure" # replace, delete, or comment-out the following if event.widget != self.master: if self.w != -1: return x = int(self.master.winfo_x()) y = int(self.master.winfo_y()) w = int(self.master.winfo_width()) h = int(self.master.winfo_height()) if (self.x, self.y, self.w, self.h) == (-1, -1, -1, -1): self.x, self.y, self.w, self.h = x, y, w, h if self.w != w or self.h != h: print("Master reconfigured... make resize adjustments") self.w = w self.h = h
class _full_combo: def __init__(self, master): grid_frame = Frame( master ) self.grid_frame = grid_frame grid_frame.pack(expand=1, fill=BOTH) self.master = master self.x, self.y, self.w, self.h = 10, 10, 519, 326 self.master.title("full_combo") self.RadioGroup_1_StringVar = StringVar() self.make_Button_1( self.grid_frame ) # Button: at Main(1,1) self.make_Notebook_1( self.grid_frame ) # Notebook: at Main(1,2) self.make_Tab_1( self.Notebook_1 ) # Tab: Small : at Notebook_1(1,1) self.make_Tab_2( self.Notebook_1 ) # Tab: Medium : at Notebook_1(1,2) self.make_Tab_3( self.Notebook_1 ) # Tab: Large : at Notebook_1(1,3) self.make_Canvas_1( self.Tab_1 ) # Canvas: at Tab_1(1,3) self.make_Frame_1( self.Tab_1 ) # Frame: at Tab_1(1,2) self.make_Checkbutton_2( self.Frame_1 ) # Checkbutton: at Frame_1(1,1) self.make_Combobox_2( self.Frame_1 ) # Combobox: Mine Yours Ours : at Frame_1(2,1) self.make_Entry_2( self.Frame_1 ) # Entry: at Frame_1(3,1) self.make_LabelFrame_1( self.Tab_2 ) # LabelFrame: Left : at Tab_2(1,1) self.make_LabelFrame_2( self.Tab_2 ) # LabelFrame: Right : at Tab_2(1,2) self.make_Listbox_1( self.LabelFrame_1 ) # Listbox: at LabelFrame_1(1,1) self.make_Message_1( self.LabelFrame_1 ) # Message: at LabelFrame_1(2,1) self.make_Menubutton_1( self.LabelFrame_2 ) # Menubutton: at LabelFrame_2(1,1) self.make_Notebook_2( self.LabelFrame_2 ) # Notebook: at LabelFrame_2(2,1) self.make_Tab_4( self.Notebook_2 ) # Tab: at Notebook_2(1,1) self.make_Tab_5( self.Notebook_2 ) # Tab: at Notebook_2(1,2) self.make_RadioGroup_1( self.Tab_4 ) # RadioGroup: at Tab_4(1,1) self.make_Radiobutton_1( self.RadioGroup_1 ) # Radiobutton: 1 : at RadioGroup_1(2,1) self.make_Radiobutton_2( self.RadioGroup_1 ) # Radiobutton: 2 : at RadioGroup_1(3,1) self.make_Radiobutton_3( self.RadioGroup_1 ) # Radiobutton: 3 : at RadioGroup_1(4,1) self.make_Radiobutton_4( self.RadioGroup_1 ) # Radiobutton: 4 : at RadioGroup_1(5,1) self.make_Scale_1( self.Tab_5 ) # Scale: 2.5 to 7.5 : at Tab_5(2,1) self.make_Spinbox_1( self.Tab_5 ) # Spinbox: 1 to 10 : at Tab_5(3,1) self.make_Button_2( self.Tab_3 ) # Button: at Tab_3(3,1) self.make_Text_1( self.Tab_3 ) # Text: at Tab_3(2,1) self.make_Treeview_1( self.Tab_3 ) # Treeview: at Tab_3(2,2) self.grid_frame.rowconfigure(1, weight=1) self.Tab_1.rowconfigure(1, weight=1) self.Tab_2.rowconfigure(1, weight=1) self.LabelFrame_1.columnconfigure(1, weight=1) self.grid_frame.columnconfigure(2, weight=1) self.Tab_2.columnconfigure(2, weight=1) self.Tab_1.columnconfigure(3, weight=1) self.Tab_2.columnconfigure(1, weight=1) self.RadioGroup_1_StringVar.set("1") self.RadioGroup_1_StringVar_traceName = self.RadioGroup_1_StringVar.trace_variable("w", self.RadioGroup_1_StringVar_Callback) # >>>>>>insert any user code below this comment for section "top_of_init" # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Button_1" def make_Button_1(self, frame): """ Button: at Main(1,1)""" self.Button_1 = Button( frame , text="Button_1", width="15", anchor="e") self.Button_1.grid(row=1, column=1, sticky="s") # >>>>>>insert any user code below this comment for section "make_Button_1" self.Button_1.bind("<ButtonRelease-1>", self.Button_1_Click) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Notebook_1" def make_Notebook_1(self, frame): """ Notebook: at Main(1,2)""" self.Notebook_1 = Notebook ( frame , width="400", height="300") self.Notebook_1.grid(row=1, column=2, sticky="nsew") # >>>>>>insert any user code below this comment for section "make_Notebook_1" # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Tab_1" def make_Tab_1(self, frame): """ Tab: Small : at Notebook_1(1,1)""" self.Tab_1 = Frame( frame ) self.Notebook_1.add( self.Tab_1, text="Small" ) # >>>>>>insert any user code below this comment for section "make_Tab_1" # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Tab_2" def make_Tab_2(self, frame): """ Tab: Medium : at Notebook_1(1,2)""" self.Tab_2 = Frame( frame ) self.Notebook_1.add( self.Tab_2, text="Medium" ) # >>>>>>insert any user code below this comment for section "make_Tab_2" # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Tab_3" def make_Tab_3(self, frame): """ Tab: Large : at Notebook_1(1,3)""" self.Tab_3 = Frame( frame ) self.Notebook_1.add( self.Tab_3, text="Large" ) # >>>>>>insert any user code below this comment for section "make_Tab_3" # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Canvas_1" def make_Canvas_1(self, frame): """ Canvas: at Tab_1(1,3)""" self.Canvas_1 = Canvas( frame , height="50", width="60") self.Canvas_1.grid(row=1, column=3, sticky="nsew") # >>>>>>insert any user code below this comment for section "make_Canvas_1" self.Canvas_1.config(bg='#ffffcc') self.Canvas_1.bind("<ButtonRelease-1>", self.Canvas_1_Click) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Frame_1" def make_Frame_1(self, frame): """ Frame: at Tab_1(1,2)""" self.Frame_1 = Frame( frame , width="60", height="50") self.Frame_1.grid(row=1, column=2, sticky="n") # >>>>>>insert any user code below this comment for section "make_Frame_1" # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Checkbutton_2" def make_Checkbutton_2(self, frame): """ Checkbutton: at Frame_1(1,1)""" self.Checkbutton_2 = Checkbutton( frame , text="Checkbutton_2", width="15", anchor="e") self.Checkbutton_2.grid(row=1, column=1) self.Checkbutton_2_StringVar = StringVar() # >>>>>>insert any user code below this comment for section "make_Checkbutton_2" self.Checkbutton_2.configure(variable=self.Checkbutton_2_StringVar, onvalue="yes", offvalue="no") self.Checkbutton_2_StringVar.set("no") self.Checkbutton_2_StringVar_traceName = self.Checkbutton_2_StringVar.trace_variable("w", self.Checkbutton_2_StringVar_Callback) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Combobox_2" def make_Combobox_2(self, frame): """ Combobox: Mine Yours Ours : at Frame_1(2,1)""" self.Combobox_2 = Combobox( frame , text="Combobox_2", values="Mine Yours Ours") self.Combobox_2.grid(row=2, column=1) self.Combobox_2_StringVar = StringVar() # >>>>>>insert any user code below this comment for section "make_Combobox_2" self.Combobox_2.configure(textvariable=self.Combobox_2_StringVar) self.Combobox_2_StringVar.set( "Mine" ) self.Combobox_2_StringVar_traceName = self.Combobox_2_StringVar.trace_variable("w", self.Combobox_2_StringVar_Callback) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Entry_2" def make_Entry_2(self, frame): """ Entry: at Frame_1(3,1)""" self.Entry_2 = Entry( frame , width="15") self.Entry_2.grid(row=3, column=1) self.Entry_2_StringVar = StringVar() # >>>>>>insert any user code below this comment for section "make_Entry_2" self.Entry_2.configure(textvariable=self.Entry_2_StringVar) self.Entry_2_StringVar_traceName = self.Entry_2_StringVar.trace_variable("w", self.Entry_2_StringVar_Callback) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_LabelFrame_1" def make_LabelFrame_1(self, frame): """ LabelFrame: Left : at Tab_2(1,1)""" self.LabelFrame_1 = LabelFrame( frame , text="Left", width="60", height="50") self.LabelFrame_1.grid(row=1, column=1, sticky="nsew") # >>>>>>insert any user code below this comment for section "make_LabelFrame_1" # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_LabelFrame_2" def make_LabelFrame_2(self, frame): """ LabelFrame: Right : at Tab_2(1,2)""" self.LabelFrame_2 = LabelFrame( frame , text="Right", width="60", height="50") self.LabelFrame_2.grid(row=1, column=2, sticky="nsew") # >>>>>>insert any user code below this comment for section "make_LabelFrame_2" # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Listbox_1" def make_Listbox_1(self, frame): """ Listbox: at LabelFrame_1(1,1)""" self.Listbox_1 = Listbox( frame , height="12", width="30") self.Listbox_1.grid(row=1, column=1) # >>>>>>insert any user code below this comment for section "make_Listbox_1" # Edit the Listbox Entries self.Listbox_1.insert(END, "apples") self.Listbox_1.insert(END, "oranges") self.Listbox_1.insert(END, "grapes") self.Listbox_1.bind("<ButtonRelease-1>", self.Listbox_1_Click) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Message_1" def make_Message_1(self, frame): """ Message: at LabelFrame_1(2,1)""" self.Message_1 = Message( frame , text="Message_1", width="55", anchor="e") self.Message_1.grid(row=2, column=1, sticky="ew") # >>>>>>insert any user code below this comment for section "make_Message_1" # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Menubutton_1" def make_Menubutton_1(self, frame): """ Menubutton: at LabelFrame_2(1,1)""" self.Menubutton_1 = Menubutton( frame , text="Menubutton_1", width="15", anchor="e") self.Menubutton_1.grid(row=1, column=1) self.Menubutton_1_StringVar = StringVar() # >>>>>>insert any user code below this comment for section "make_Menubutton_1" self.Menubutton_1.configure(textvariable=self.Menubutton_1_StringVar, text="Select") self.Menubutton_1_StringVar.set("Select") self.Menubutton_1_StringVar_traceName = self.Menubutton_1_StringVar.trace_variable("w", self.Menubutton_1_StringVar_Callback) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Notebook_2" def make_Notebook_2(self, frame): """ Notebook: at LabelFrame_2(2,1)""" self.Notebook_2 = Notebook ( frame , width="400", height="300") self.Notebook_2.grid(row=2, column=1) # >>>>>>insert any user code below this comment for section "make_Notebook_2" # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Tab_4" def make_Tab_4(self, frame): """ Tab: at Notebook_2(1,1)""" self.Tab_4 = Frame( frame ) self.Notebook_2.add( self.Tab_4, text="Tab_4" ) # >>>>>>insert any user code below this comment for section "make_Tab_4" # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Tab_5" def make_Tab_5(self, frame): """ Tab: at Notebook_2(1,2)""" self.Tab_5 = Frame( frame ) self.Notebook_2.add( self.Tab_5, text="Tab_5" ) # >>>>>>insert any user code below this comment for section "make_Tab_5" # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_RadioGroup_1" def make_RadioGroup_1(self, frame): """ RadioGroup: at Tab_4(1,1)""" self.RadioGroup_1 = LabelFrame( frame , width="60", height="50") self.RadioGroup_1.grid(row=1, column=1) # >>>>>>insert any user code below this comment for section "make_RadioGroup_1" # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Radiobutton_1" def make_Radiobutton_1(self, frame): """ Radiobutton: 1 : at RadioGroup_1(2,1)""" self.Radiobutton_1 = Radiobutton( frame , text="Radiobutton_1", value="1", width="15", anchor="e") self.Radiobutton_1.grid(row=2, column=1) # >>>>>>insert any user code below this comment for section "make_Radiobutton_1" self.Radiobutton_1.configure(variable=self.RadioGroup_1_StringVar) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Radiobutton_2" def make_Radiobutton_2(self, frame): """ Radiobutton: 2 : at RadioGroup_1(3,1)""" self.Radiobutton_2 = Radiobutton( frame , text="Radiobutton_2", value="2", width="15") self.Radiobutton_2.grid(row=3, column=1) # >>>>>>insert any user code below this comment for section "make_Radiobutton_2" self.Radiobutton_2.configure(variable=self.RadioGroup_1_StringVar) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Radiobutton_3" def make_Radiobutton_3(self, frame): """ Radiobutton: 3 : at RadioGroup_1(4,1)""" self.Radiobutton_3 = Radiobutton( frame , text="Radiobutton_3", value="3", width="15") self.Radiobutton_3.grid(row=4, column=1) # >>>>>>insert any user code below this comment for section "make_Radiobutton_3" self.Radiobutton_3.configure(variable=self.RadioGroup_1_StringVar) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Radiobutton_4" def make_Radiobutton_4(self, frame): """ Radiobutton: 4 : at RadioGroup_1(5,1)""" self.Radiobutton_4 = Radiobutton( frame , text="Radiobutton_4", value="4", width="15") self.Radiobutton_4.grid(row=5, column=1) # >>>>>>insert any user code below this comment for section "make_Radiobutton_4" self.Radiobutton_4.configure(variable=self.RadioGroup_1_StringVar) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Scale_1" def make_Scale_1(self, frame): """ Scale: 2.5 to 7.5 : at Tab_5(2,1)""" self.Scale_1 = Scale( frame , digits="3", tickinterval="1", to="7.5", from_="2.5", resolution=".5") self.Scale_1.grid(row=2, column=1) self.Scale_1_StringVar = StringVar() # >>>>>>insert any user code below this comment for section "make_Scale_1" self.Scale_1.configure(variable=self.Scale_1_StringVar) self.Scale_1_StringVar_traceName = self.Scale_1_StringVar.trace_variable("w", self.Scale_1_StringVar_Callback) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Spinbox_1" def make_Spinbox_1(self, frame): """ Spinbox: 1 to 10 : at Tab_5(3,1)""" self.Spinbox_1 = Spinbox( frame , to="10", text="Spinbox_1", width="15", from_="1") self.Spinbox_1.grid(row=3, column=1) self.Spinbox_1_StringVar = StringVar() # >>>>>>insert any user code below this comment for section "make_Spinbox_1" self.Spinbox_1.configure(textvariable=self.Spinbox_1_StringVar, to="10", from_="1") self.Spinbox_1_StringVar.set("1") self.Spinbox_1_StringVar_traceName = self.Spinbox_1_StringVar.trace_variable("w", self.Spinbox_1_StringVar_Callback) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Button_2" def make_Button_2(self, frame): """ Button: at Tab_3(3,1)""" self.Button_2 = Button( frame , text="Button_2", width="15") self.Button_2.grid(row=3, column=1) # >>>>>>insert any user code below this comment for section "make_Button_2" self.Button_2.bind("<ButtonRelease-1>", self.Button_2_Click) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Text_1" def make_Text_1(self, frame): """ Text: at Tab_3(2,1)""" lbframe = Frame( frame ) self.Text_1_frame = lbframe vbar=Scrollbar(lbframe, orient=VERTICAL) self.Text_1 = Text(lbframe, width="40", height="12", yscrollcommand=vbar.set) vbar.config(command=self.Text_1.yview) vbar.grid(row=0, column=1, sticky='ns') self.Text_1.grid(row=0, column=0) self.Text_1_frame.grid(row=2, column=1) # >>>>>>insert any user code below this comment for section "make_Text_1" # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Treeview_1" def make_Treeview_1(self, frame): """ Treeview: at Tab_3(2,2)""" self.Treeview_1 = Treeview( frame ) self.Treeview_1.grid(row=2, column=2) # >>>>>>insert any user code below this comment for section "make_Treeview_1" self.Treeview_1.insert('', 'end', 'widgets', text='Widget Tour') # Same thing, but inserted as first child: self.Treeview_1.insert('', 0, 'gallery', text='Treeview_1') # Inserted underneath an existing node: self.Treeview_1.insert('widgets', 'end', text='Button') self.Treeview_1.insert('widgets', 'end', text='Canvas') self.Treeview_1.insert('widgets', 'end', text='Checkbutton') self.Treeview_1.insert('widgets', 'end', text='Combobox') self.Treeview_1.insert('widgets', 'end', text='Entry') self.Treeview_1.insert('widgets', 'end', text='Frame') self.Treeview_1.insert('widgets', 'end', text='Label') self.Treeview_1.insert('widgets', 'end', text='LabelFrame') self.Treeview_1.insert('widgets', 'end', text='Listbox') self.Treeview_1.insert('widgets', 'end', text='Menubutton') self.Treeview_1.insert('widgets', 'end', text='Message') self.Treeview_1.insert('widgets', 'end', text='Notebook') self.Treeview_1.insert('widgets', 'end', text='OptionMenu') self.Treeview_1.insert('widgets', 'end', text='Progressbar') self.Treeview_1.insert('widgets', 'end', text='RadioGroup') self.Treeview_1.insert('widgets', 'end', text='Radiobutton') self.Treeview_1.insert('widgets', 'end', text='Scale') self.Treeview_1.insert('widgets', 'end', text='Separator') self.Treeview_1.insert('widgets', 'end', text='Spinbox') self.Treeview_1.insert('widgets', 'end', text='Tab') self.Treeview_1.insert('widgets', 'end', text='Text') self.Treeview_1.insert('widgets', 'end', text='Treeview') # Treeview chooses the id: id = self.Treeview_1.insert('', 'end', text='Tutorial') self.Treeview_1.insert(id, 'end', text='Tree') self.Treeview_1.bind("<ButtonRelease-1>", self.Treeview_1_Click) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "Button_1_Click" def Button_1_Click(self, event): #bind method for component ID=Button_1 """ Button: at Main(1,1)""" pass # >>>>>>insert any user code below this comment for section "Button_1_Click" # replace, delete, or comment-out the following print( "executed method Button_1_Click" ) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "Canvas_1_Click" def Canvas_1_Click(self, event): #bind method for component ID=Canvas_1 """ Canvas: at Tab_1(1,3)""" pass # >>>>>>insert any user code below this comment for section "Canvas_1_Click" # replace, delete, or comment-out the following print( "executed method Canvas_1_Click" ) print( "clicked in canvas at x,y =",event.x,event.y ) w = int(self.Canvas_1.cget("width")) h = int(self.Canvas_1.cget("height")) self.Canvas_1.create_rectangle((2, 2, w+1, h+1), outline="blue") self.Canvas_1.create_line(0, 0, w+2, h+2, fill="red") x = int(event.x) y = int(event.y) print( "event x,y=",x,y ) self.Canvas_1.create_text(x,y, text="NE", fill="green", anchor=NE) self.Canvas_1.create_text(x,y, text="SW", fill="magenta", anchor=SW) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "Listbox_1_Click" def Listbox_1_Click(self, event): #bind method for component ID=Listbox_1 """ Listbox: at LabelFrame_1(1,1)""" pass # >>>>>>insert any user code below this comment for section "Listbox_1_Click" # replace, delete, or comment-out the following print( "executed method Listbox_1_Click" ) print( "current selection(s) =",self.Listbox_1.curselection() ) labelL = [] for i in self.Listbox_1.curselection(): labelL.append( self.Listbox_1.get(i)) print( "current label(s) =",labelL ) # use self.Listbox_1.insert(0, "item zero") # self.Listbox_1.insert(index, "item i") # OR # self.Listbox_1.insert(END, "item end") # to insert items into the list box # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "Button_2_Click" def Button_2_Click(self, event): #bind method for component ID=Button_2 """ Button: at Tab_3(3,1)""" pass # >>>>>>insert any user code below this comment for section "Button_2_Click" # replace, delete, or comment-out the following print( "executed method Button_2_Click" ) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "Treeview_1_Click" def Treeview_1_Click(self, event): #bind method for component ID=Treeview_1 """ Treeview: at Tab_3(2,2)""" pass # >>>>>>insert any user code below this comment for section "Treeview_1_Click" # replace, delete, or comment-out the following print( "executed method Treeview_1_Click" ) curItem = self.Treeview_1.focus() print( "current Treeview item(s) =",self.Treeview_1.item( curItem ) ) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "Checkbutton_2_StringVar_traceName" def Checkbutton_2_StringVar_Callback(self, varName, index, mode): """ Checkbutton: at Frame_1(1,1)""" pass # >>>>>>insert any user code below this comment for section "Checkbutton_2_StringVar_traceName" # replace, delete, or comment-out the following print( "Checkbutton_2_StringVar_Callback varName, index, mode",varName, index, mode ) print( " new StringVar value =",self.Checkbutton_2_StringVar.get() ) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "Combobox_2_StringVar_traceName" def Combobox_2_StringVar_Callback(self, varName, index, mode): """ Combobox: Mine Yours Ours : at Frame_1(2,1)""" pass # >>>>>>insert any user code below this comment for section "Combobox_2_StringVar_traceName" # replace, delete, or comment-out the following print( "Combobox_2_StringVar_Callback varName, index, mode",varName, index, mode ) print( " new StringVar value =",self.Combobox_2_StringVar.get() ) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "Entry_2_StringVar_traceName" def Entry_2_StringVar_Callback(self, varName, index, mode): """ Entry: at Frame_1(3,1)""" pass # >>>>>>insert any user code below this comment for section "Entry_2_StringVar_traceName" # replace, delete, or comment-out the following print( "Entry_2_StringVar_Callback varName, index, mode",varName, index, mode ) print( " new StringVar value =",self.Entry_2_StringVar.get() ) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "Menubutton_1_StringVar_traceName" def Menubutton_1_StringVar_Callback(self, varName, index, mode): """ Menubutton: at LabelFrame_2(1,1)""" pass # >>>>>>insert any user code below this comment for section "Menubutton_1_StringVar_traceName" # replace, delete, or comment-out the following print( "Menubutton_1_StringVar_Callback varName, index, mode",varName, index, mode ) print( " new StringVar value =",self.Menubutton_1_StringVar.get() ) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "Scale_1_StringVar_traceName" def Scale_1_StringVar_Callback(self, varName, index, mode): """ Scale: 2.5 to 7.5 : at Tab_5(2,1)""" pass # >>>>>>insert any user code below this comment for section "Scale_1_StringVar_traceName" # replace, delete, or comment-out the following print( "Scale_1_StringVar_Callback varName, index, mode",varName, index, mode ) print( " new StringVar value =",self.Scale_1_StringVar.get() ) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "Spinbox_1_StringVar_traceName" def Spinbox_1_StringVar_Callback(self, varName, index, mode): """ Spinbox: 1 to 10 : at Tab_5(3,1)""" pass # >>>>>>insert any user code below this comment for section "Spinbox_1_StringVar_traceName" # replace, delete, or comment-out the following print( "Spinbox_1_StringVar_Callback varName, index, mode",varName, index, mode ) print( " new StringVar value =",self.Spinbox_1_StringVar.get() ) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "RadioGroup_1_StringVar_traceName" def RadioGroup_1_StringVar_Callback(self, varName, index, mode): """ RadioGroup: at Tab_4(1,1)""" pass # >>>>>>insert any user code below this comment for section "RadioGroup_1_StringVar_traceName" # replace, delete, or comment-out the following print( "RadioGroup_1_StringVar_Callback varName, index, mode",varName, index, mode ) print( " new StringVar value =",self.RadioGroup_1_StringVar.get() )
class _cross_platform_fonts(_Dialog): def body(self, master): dialogframe = Frame(master, width=523, height=346) self.dialogframe = dialogframe dialogframe.pack() self.RadioGroup_1_StringVar = StringVar() self.make_Entry_2(self.dialogframe) # Entry: at Main(1,2) self.make_LabelFrame_1( self.dialogframe) # LabelFrame: Attributes : at Main(2,4) self.make_Label_3( self.dialogframe ) # Label: (see sample text above) : at Main(9,1) self.make_Label_4( self.dialogframe) # Label: ABCD efg 123.0 : at Main(8,1) self.make_Label_6( self.dialogframe ) # Label: Courier 10 normal italic underline overstrike : at Main(0,1) self.make_Label_7(self.dialogframe) # Label: at Main(2,3) self.make_Label_8( self.dialogframe) # Label: System Fonts : at Main(0,5) self.make_Listbox_1(self.dialogframe) # Listbox: at Main(2,2) self.make_Listbox_2(self.dialogframe) # Listbox: at Main(1,5) self.make_RadioGroup_1( self.dialogframe ) # RadioGroup: Cross Platform Fonts : at Main(2,1) self.make_Checkbutton_1( self.LabelFrame_1) # Checkbutton: Bold : at LabelFrame_1(1,1) self.make_Checkbutton_2( self.LabelFrame_1) # Checkbutton: Italic : at LabelFrame_1(2,1) self.make_Checkbutton_3( self.LabelFrame_1) # Checkbutton: Underline : at LabelFrame_1(3,1) self.make_Checkbutton_4( self.LabelFrame_1 ) # Checkbutton: Overstrike : at LabelFrame_1(4,1) self.make_Radiobutton_1( self.RadioGroup_1) # Radiobutton: Courier : at RadioGroup_1(1,0) self.make_Radiobutton_2( self.RadioGroup_1) # Radiobutton: Helvetica : at RadioGroup_1(2,0) self.make_Radiobutton_3( self.RadioGroup_1) # Radiobutton: Times : at RadioGroup_1(3,0) self.make_Radiobutton_4( self.RadioGroup_1 ) # Radiobutton: TkDefaultFont : at RadioGroup_1(4,0) self.make_Radiobutton_5( self.RadioGroup_1 ) # Radiobutton: Platform Specific : at RadioGroup_1(6,0) self.make_Radiobutton_6( self.RadioGroup_1) # Radiobutton: Symbol : at RadioGroup_1(5,0) self.RadioGroup_1_StringVar.set("1") self.RadioGroup_1_StringVar_traceName = self.RadioGroup_1_StringVar.trace_variable( "w", self.RadioGroup_1_StringVar_Callback) # >>>>>>insert any user code below this comment for section "top_of_init" self.RadioGroup_1_StringVar.set("2") # make Helvetica the default self.current_font_name = 'Helvetica' self.ignore_entry_change = False # used when Listbox sets Entry self.Entry_2_StringVar.set('10') def set_current_state(self): sL = [self.current_font_name] points = self.Entry_2_StringVar.get().strip() try: points = int(points.strip()) except: points = 10 if points: sL.append(points) else: sL.append(10) if self.Checkbutton_1_StringVar.get() == 'yes': sL.append('bold') else: sL.append('normal') if self.Checkbutton_2_StringVar.get() == 'yes': sL.append('italic') else: sL.append('roman') if self.Checkbutton_3_StringVar.get() == 'yes': sL.append('underline') if self.Checkbutton_4_StringVar.get() == 'yes': sL.append('overstrike') self.full_font_desc = tuple(sL) self.Label_6.configure(text=self.full_font_desc) self.Label_4.configure(font=self.full_font_desc) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Entry_2" def make_Entry_2(self, frame): """ Entry: at Main(1,2)""" self.Entry_2 = Entry(frame, width="4") self.Entry_2.grid(row=1, column=2, sticky="w") self.Entry_2_StringVar = StringVar() # >>>>>>insert any user code below this comment for section "make_Entry_2" self.Entry_2.configure(textvariable=self.Entry_2_StringVar) self.Entry_2_StringVar_traceName = self.Entry_2_StringVar.trace_variable( "w", self.Entry_2_StringVar_Callback) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_LabelFrame_1" def make_LabelFrame_1(self, frame): """ LabelFrame: Attributes : at Main(2,4)""" self.LabelFrame_1 = LabelFrame(frame, text="Attributes", width="60", height="50") self.LabelFrame_1.grid(row=2, column=4, sticky="n", rowspan="2") # >>>>>>insert any user code below this comment for section "make_LabelFrame_1" # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Label_3" def make_Label_3(self, frame): """ Label: (see sample text above) : at Main(9,1)""" self.Label_3 = Label(frame, text="(see sample text above)", width="30") self.Label_3.grid(row=9, column=1, columnspan="5") # >>>>>>insert any user code below this comment for section "make_Label_3" # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Label_4" def make_Label_4(self, frame): """ Label: ABCD efg 123.0 : at Main(8,1)""" self.Label_4 = Label(frame, text="ABCD efg 123.0", width="14") self.Label_4.grid(row=8, column=1, sticky="ew", columnspan="5") # >>>>>>insert any user code below this comment for section "make_Label_4" # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Label_6" def make_Label_6(self, frame): """ Label: Courier 10 normal italic underline overstrike : at Main(0,1)""" self.Label_6 = Label( frame, text="Courier 10 normal italic underline overstrike", width="30", font="TkDefaultFont 12") self.Label_6.grid(row=0, column=1, sticky="ew", columnspan="4") # >>>>>>insert any user code below this comment for section "make_Label_6" # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Label_7" def make_Label_7(self, frame): """ Label: at Main(2,3)""" self.Label_7 = Label(frame, text="", width="3") self.Label_7.grid(row=2, column=3) # >>>>>>insert any user code below this comment for section "make_Label_7" # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Label_8" def make_Label_8(self, frame): """ Label: System Fonts : at Main(0,5)""" self.Label_8 = Label(frame, text="System Fonts", width="15") self.Label_8.grid(row=0, column=5, sticky="s") # >>>>>>insert any user code below this comment for section "make_Label_8" # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Listbox_1" def make_Listbox_1(self, frame): """ Listbox: at Main(2,2)""" lbframe = Frame(frame) self.Listbox_1_frame = lbframe vbar = Scrollbar(lbframe, orient=VERTICAL) self.Listbox_1 = Listbox(lbframe, width="4", borderwidth="4", height="10", yscrollcommand=vbar.set) vbar.config(command=self.Listbox_1.yview) vbar.grid(row=0, column=1, sticky='ns') self.Listbox_1.grid(row=0, column=0) self.Listbox_1_frame.grid(row=2, column=2, sticky="nsw") # >>>>>>insert any user code below this comment for section "make_Listbox_1" self.Listbox_1.configure( exportselection=False) # stay highlighted after focus leaves # Edit the Listbox Entries self.font_sizeL = [ "%i" % i for i in (list(range(6, 17)) + list(range(18, 32, 2)) + [42, 48, 54, 60, 72]) ] for s in self.font_sizeL: self.Listbox_1.insert(END, s) self.Listbox_1.bind("<ButtonRelease-1>", self.Listbox_1_Click) self.Listbox_1.bind('<<ListboxSelect>>', self.Listbox_1_Click) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Listbox_2" def make_Listbox_2(self, frame): """ Listbox: at Main(1,5)""" lbframe = Frame(frame) self.Listbox_2_frame = lbframe vbar = Scrollbar(lbframe, orient=VERTICAL) self.Listbox_2 = Listbox(lbframe, width="25", height="15", yscrollcommand=vbar.set) vbar.config(command=self.Listbox_2.yview) vbar.grid(row=0, column=1, sticky='ns') self.Listbox_2.grid(row=0, column=0) self.Listbox_2_frame.grid(row=1, column=5, sticky="ns", rowspan="7") # >>>>>>insert any user code below this comment for section "make_Listbox_2" self.Listbox_2.configure( exportselection=False) # stay highlighted after focus leaves self.sys_fonts = list(set(families())) self.sys_fonts.sort() for s in self.sys_fonts: self.Listbox_2.insert(END, s) self.Listbox_2.bind("<ButtonRelease-1>", self.Listbox_2_Click) self.Listbox_2.bind('<<ListboxSelect>>', self.Listbox_2_Click) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_RadioGroup_1" def make_RadioGroup_1(self, frame): """ RadioGroup: Cross Platform Fonts : at Main(2,1)""" self.RadioGroup_1 = LabelFrame(frame, text="Cross Platform Fonts", width="60", height="50") self.RadioGroup_1.grid(row=2, column=1, sticky="n", rowspan="2") # >>>>>>insert any user code below this comment for section "make_RadioGroup_1" # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Checkbutton_1" def make_Checkbutton_1(self, frame): """ Checkbutton: Bold : at LabelFrame_1(1,1)""" self.Checkbutton_1 = Checkbutton(frame, text="Bold", width="15", anchor="w") self.Checkbutton_1.grid(row=1, column=1) self.Checkbutton_1_StringVar = StringVar() # >>>>>>insert any user code below this comment for section "make_Checkbutton_1" self.Checkbutton_1.configure(variable=self.Checkbutton_1_StringVar, onvalue="yes", offvalue="no") self.Checkbutton_1_StringVar.set("no") self.Checkbutton_1_StringVar_traceName = self.Checkbutton_1_StringVar.trace_variable( "w", self.Checkbutton_1_StringVar_Callback) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Checkbutton_2" def make_Checkbutton_2(self, frame): """ Checkbutton: Italic : at LabelFrame_1(2,1)""" self.Checkbutton_2 = Checkbutton(frame, text="Italic", width="15", anchor="w") self.Checkbutton_2.grid(row=2, column=1) self.Checkbutton_2_StringVar = StringVar() # >>>>>>insert any user code below this comment for section "make_Checkbutton_2" self.Checkbutton_2.configure(variable=self.Checkbutton_2_StringVar, onvalue="yes", offvalue="no") self.Checkbutton_2_StringVar.set("no") self.Checkbutton_2_StringVar_traceName = self.Checkbutton_2_StringVar.trace_variable( "w", self.Checkbutton_2_StringVar_Callback) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Checkbutton_3" def make_Checkbutton_3(self, frame): """ Checkbutton: Underline : at LabelFrame_1(3,1)""" self.Checkbutton_3 = Checkbutton(frame, text="Underline", width="15", anchor="w") self.Checkbutton_3.grid(row=3, column=1) self.Checkbutton_3_StringVar = StringVar() # >>>>>>insert any user code below this comment for section "make_Checkbutton_3" self.Checkbutton_3.configure(variable=self.Checkbutton_3_StringVar, onvalue="yes", offvalue="no") self.Checkbutton_3_StringVar.set("no") self.Checkbutton_3_StringVar_traceName = self.Checkbutton_3_StringVar.trace_variable( "w", self.Checkbutton_3_StringVar_Callback) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Checkbutton_4" def make_Checkbutton_4(self, frame): """ Checkbutton: Overstrike : at LabelFrame_1(4,1)""" self.Checkbutton_4 = Checkbutton(frame, text="Overstrike", width="15", anchor="w") self.Checkbutton_4.grid(row=4, column=1) self.Checkbutton_4_StringVar = StringVar() # >>>>>>insert any user code below this comment for section "make_Checkbutton_4" self.Checkbutton_4.configure(variable=self.Checkbutton_4_StringVar, onvalue="yes", offvalue="no") self.Checkbutton_4_StringVar.set("no") self.Checkbutton_4_StringVar_traceName = self.Checkbutton_4_StringVar.trace_variable( "w", self.Checkbutton_4_StringVar_Callback) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Radiobutton_1" def make_Radiobutton_1(self, frame): """ Radiobutton: Courier : at RadioGroup_1(1,0)""" self.Radiobutton_1 = Radiobutton(frame, text="Courier", value="1", width="15", anchor="w") self.Radiobutton_1.grid(row=1, column=0) # >>>>>>insert any user code below this comment for section "make_Radiobutton_1" self.Radiobutton_1.configure(variable=self.RadioGroup_1_StringVar) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Radiobutton_2" def make_Radiobutton_2(self, frame): """ Radiobutton: Helvetica : at RadioGroup_1(2,0)""" self.Radiobutton_2 = Radiobutton(frame, text="Helvetica", value="2", width="15", anchor="w") self.Radiobutton_2.grid(row=2, column=0) # >>>>>>insert any user code below this comment for section "make_Radiobutton_2" self.Radiobutton_2.configure(variable=self.RadioGroup_1_StringVar) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Radiobutton_3" def make_Radiobutton_3(self, frame): """ Radiobutton: Times : at RadioGroup_1(3,0)""" self.Radiobutton_3 = Radiobutton(frame, text="Times", value="3", width="15", anchor="w") self.Radiobutton_3.grid(row=3, column=0) # >>>>>>insert any user code below this comment for section "make_Radiobutton_3" self.Radiobutton_3.configure(variable=self.RadioGroup_1_StringVar) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Radiobutton_4" def make_Radiobutton_4(self, frame): """ Radiobutton: TkDefaultFont : at RadioGroup_1(4,0)""" self.Radiobutton_4 = Radiobutton(frame, text="TkDefaultFont", value="4", width="15", anchor="w") self.Radiobutton_4.grid(row=4, column=0) # >>>>>>insert any user code below this comment for section "make_Radiobutton_4" self.Radiobutton_4.configure(variable=self.RadioGroup_1_StringVar) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Radiobutton_5" def make_Radiobutton_5(self, frame): """ Radiobutton: Platform Specific : at RadioGroup_1(6,0)""" self.Radiobutton_5 = Radiobutton(frame, text="Platform Specific", value="6", width="15", anchor="e") self.Radiobutton_5.grid(row=6, column=0) # >>>>>>insert any user code below this comment for section "make_Radiobutton_5" self.Radiobutton_5.configure(variable=self.RadioGroup_1_StringVar) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Radiobutton_6" def make_Radiobutton_6(self, frame): """ Radiobutton: Symbol : at RadioGroup_1(5,0)""" self.Radiobutton_6 = Radiobutton(frame, text="Symbol", value="5", width="15", anchor="w") self.Radiobutton_6.grid(row=5, column=0) # >>>>>>insert any user code below this comment for section "make_Radiobutton_6" self.Radiobutton_6.configure(variable=self.RadioGroup_1_StringVar) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "Listbox_1_Click" def Listbox_1_Click(self, event): #bind method for component ID=Listbox_1 """ Listbox: at Main(2,2)""" pass # >>>>>>insert any user code below this comment for section "Listbox_1_Click" # replace, delete, or comment-out the following #print( "executed method Listbox_1_Click" ) #print( "current selection(s) =",self.Listbox_1.curselection() ) labelL = [] for i in self.Listbox_1.curselection(): labelL.append(self.Listbox_1.get(i)) #print( "current label(s) =",labelL ) if labelL: self.ignore_entry_change = True self.Entry_2_StringVar.set(labelL[0]) self.ignore_entry_change = False # use self.Listbox_1.insert(0, "item zero") # self.Listbox_1.insert(index, "item i") # OR # self.Listbox_1.insert(END, "item end") # to insert items into the list box # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "Listbox_2_Click" def Listbox_2_Click(self, event): #bind method for component ID=Listbox_2 """ Listbox: at Main(1,5)""" pass # >>>>>>insert any user code below this comment for section "Listbox_2_Click" # replace, delete, or comment-out the following #print( "executed method Listbox_2_Click" ) #print( "current selection(s) =",self.Listbox_2.curselection() ) labelL = [] for i in self.Listbox_2.curselection(): labelL.append(self.Listbox_2.get(i)) #print( "current label(s) =",labelL ) # use self.Listbox_2.insert(0, "item zero") # self.Listbox_2.insert(index, "item i") # OR # self.Listbox_2.insert(END, "item end") # to insert items into the list box self.RadioGroup_1_StringVar.set("6") # make Helvetica the default if labelL: self.current_font_name = labelL[0] self.set_current_state() # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "Entry_2_StringVar_traceName" def Entry_2_StringVar_Callback(self, varName, index, mode): """ Entry: at Main(1,2)""" pass # >>>>>>insert any user code below this comment for section "Entry_2_StringVar_traceName" # replace, delete, or comment-out the following #print( "Entry_2_StringVar_Callback varName, index, mode",varName, index, mode ) #print( " new StringVar value =",self.Entry_2_StringVar.get() ) self.set_current_state() if self.ignore_entry_change: return # Looks like a manual change, so try to change Listbox sval = self.Entry_2_StringVar.get().strip() try: ival = int(sval) except: ival = 0 if ival and (sval in self.font_sizeL): index = self.font_sizeL.index(sval) self.Listbox_1.selection_clear(0, "end") self.Listbox_1.select_set(index) self.Listbox_1.see(index) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "Checkbutton_1_StringVar_traceName" def Checkbutton_1_StringVar_Callback(self, varName, index, mode): """ Checkbutton: Bold : at LabelFrame_1(1,1)""" pass # >>>>>>insert any user code below this comment for section "Checkbutton_1_StringVar_traceName" # replace, delete, or comment-out the following #print( "Checkbutton_1_StringVar_Callback varName, index, mode",varName, index, mode ) #print( " new StringVar value =",self.Checkbutton_1_StringVar.get() ) self.set_current_state() # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "Checkbutton_2_StringVar_traceName" def Checkbutton_2_StringVar_Callback(self, varName, index, mode): """ Checkbutton: Italic : at LabelFrame_1(2,1)""" pass # >>>>>>insert any user code below this comment for section "Checkbutton_2_StringVar_traceName" # replace, delete, or comment-out the following #print( "Checkbutton_2_StringVar_Callback varName, index, mode",varName, index, mode ) #print( " new StringVar value =",self.Checkbutton_2_StringVar.get() ) self.set_current_state() # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "Checkbutton_3_StringVar_traceName" def Checkbutton_3_StringVar_Callback(self, varName, index, mode): """ Checkbutton: Underline : at LabelFrame_1(3,1)""" pass # >>>>>>insert any user code below this comment for section "Checkbutton_3_StringVar_traceName" # replace, delete, or comment-out the following #print( "Checkbutton_3_StringVar_Callback varName, index, mode",varName, index, mode ) #print( " new StringVar value =",self.Checkbutton_3_StringVar.get() ) self.set_current_state() # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "Checkbutton_4_StringVar_traceName" def Checkbutton_4_StringVar_Callback(self, varName, index, mode): """ Checkbutton: Overstrike : at LabelFrame_1(4,1)""" pass # >>>>>>insert any user code below this comment for section "Checkbutton_4_StringVar_traceName" # replace, delete, or comment-out the following #print( "Checkbutton_4_StringVar_Callback varName, index, mode",varName, index, mode ) #print( " new StringVar value =",self.Checkbutton_4_StringVar.get() ) self.set_current_state() # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "RadioGroup_1_StringVar_traceName" def RadioGroup_1_StringVar_Callback(self, varName, index, mode): """ RadioGroup: Cross Platform Fonts : at Main(2,1)""" pass # >>>>>>insert any user code below this comment for section "RadioGroup_1_StringVar_traceName" # replace, delete, or comment-out the following #print( "RadioGroup_1_StringVar_Callback varName, index, mode",varName, index, mode ) #print( " new StringVar value =",self.RadioGroup_1_StringVar.get() ) svar = self.RadioGroup_1_StringVar.get() if svar == '1': self.current_font_name = 'Courier' elif svar == '2': self.current_font_name = 'Helvetica' elif svar == '3': self.current_font_name = 'Times' elif svar == '4': self.current_font_name = 'TkDefaultFont' elif svar == '5': self.current_font_name = 'Symbol' elif svar == '6': labelL = [] for i in self.Listbox_2.curselection(): labelL.append(self.Listbox_2.get(i)) if labelL: self.current_font_name = labelL[0] self.set_current_state() # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "dialog_validate" def validate(self): self.result = {} # return a dictionary of results self.result["Entry_2"] = self.Entry_2_StringVar.get() self.result["Checkbutton_1"] = self.Checkbutton_1_StringVar.get() self.result["Checkbutton_2"] = self.Checkbutton_2_StringVar.get() self.result["Checkbutton_3"] = self.Checkbutton_3_StringVar.get() self.result["Checkbutton_4"] = self.Checkbutton_4_StringVar.get() self.result["RadioGroup_1"] = self.RadioGroup_1_StringVar.get() # >>>>>>insert any user code below this comment for section "dialog_validate" # set values in "self.result" dictionary for return # for example... # self.result["age"] = self.Entry_2_StringVar.get() self.result = {} t = self.full_font_desc self.result["full_font_desc"] = t # return the tuple self.result["full_font_str"] = t[0].replace( ' ', '\ ') + ' %i ' % t[1] + ' '.join(t[2:]) return 1 # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "end" def apply(self): pass
class _named_color_picker(_Dialog): def body(self, master): dialogframe = Frame(master, width=536, height=225) self.dialogframe = dialogframe dialogframe.pack() self.RadioGroup_1_StringVar = StringVar() self.make_LabelFrame_1( self.dialogframe ) # LabelFrame: Colors : at Main(5,1) self.make_Label_1( self.dialogframe ) # Label: Left Click Background : at Main(2,1) self.make_Label_2( self.dialogframe ) # Label: Right Click Foreground : at Main(3,1) self.make_Label_3( self.dialogframe ) # Label: Luminance and Contrast Ratio shown above : at Main(4,1) self.make_RadioGroup_1( self.dialogframe ) # RadioGroup: Sort By: : at Main(1,1) self.make_Radiobutton_1( self.RadioGroup_1 ) # Radiobutton: HSV hue : at RadioGroup_1(1,1) self.make_Radiobutton_2( self.RadioGroup_1 ) # Radiobutton: W3 Luminance : at RadioGroup_1(1,2) self.make_Radiobutton_3( self.RadioGroup_1 ) # Radiobutton: HEX String : at RadioGroup_1(1,3) self.make_Radiobutton_4( self.RadioGroup_1 ) # Radiobutton: Color Name : at RadioGroup_1(1,4) self.RadioGroup_1_StringVar.set("1") self.RadioGroup_1_StringVar_traceName = self.RadioGroup_1_StringVar.trace_variable("w", self.RadioGroup_1_StringVar_Callback) # >>>>>>insert any user code below this comment for section "top_of_init" # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_LabelFrame_1" def make_LabelFrame_1(self, frame): """ LabelFrame: Colors : at Main(5,1)""" self.LabelFrame_1 = LabelFrame( frame , text="Colors", width="60", height="50") self.LabelFrame_1.grid(row=5, column=1) # >>>>>>insert any user code below this comment for section "make_LabelFrame_1" # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Label_1" def make_Label_1(self, frame): """ Label: Left Click Background : at Main(2,1)""" self.Label_1 = Label( frame , text="Left Click Background", width="30", font="Times\ New\ Roman 20 bold roman") self.Label_1.grid(row=2, column=1, sticky="ew") # >>>>>>insert any user code below this comment for section "make_Label_1" # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Label_2" def make_Label_2(self, frame): """ Label: Right Click Foreground : at Main(3,1)""" self.Label_2 = Label( frame , text="Right Click Foreground", width="30", font="Times\ New\ Roman 20 bold roman") self.Label_2.grid(row=3, column=1, sticky="ew") # >>>>>>insert any user code below this comment for section "make_Label_2" # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Label_3" def make_Label_3(self, frame): """ Label: Luminance and Contrast Ratio shown above : at Main(4,1)""" self.Label_3 = Label( frame , text="Luminance and Contrast Ratio shown above", width="45") self.Label_3.grid(row=4, column=1, sticky="e") # >>>>>>insert any user code below this comment for section "make_Label_3" # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_RadioGroup_1" def make_RadioGroup_1(self, frame): """ RadioGroup: Sort By: : at Main(1,1)""" self.RadioGroup_1 = LabelFrame( frame , text="Sort By:", width="60", height="50") self.RadioGroup_1.grid(row=1, column=1) # >>>>>>insert any user code below this comment for section "make_RadioGroup_1" # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Radiobutton_1" def make_Radiobutton_1(self, frame): """ Radiobutton: HSV hue : at RadioGroup_1(1,1)""" self.Radiobutton_1 = Radiobutton( frame , text="HSV hue", value="1", width="15") self.Radiobutton_1.grid(row=1, column=1) # >>>>>>insert any user code below this comment for section "make_Radiobutton_1" self.Radiobutton_1.configure(variable=self.RadioGroup_1_StringVar) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Radiobutton_2" def make_Radiobutton_2(self, frame): """ Radiobutton: W3 Luminance : at RadioGroup_1(1,2)""" self.Radiobutton_2 = Radiobutton( frame , text="W3 Luminance", value="2", width="15") self.Radiobutton_2.grid(row=1, column=2) # >>>>>>insert any user code below this comment for section "make_Radiobutton_2" self.Radiobutton_2.configure(variable=self.RadioGroup_1_StringVar) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Radiobutton_3" def make_Radiobutton_3(self, frame): """ Radiobutton: HEX String : at RadioGroup_1(1,3)""" self.Radiobutton_3 = Radiobutton( frame , text="HEX String", value="3", width="15") self.Radiobutton_3.grid(row=1, column=3) # >>>>>>insert any user code below this comment for section "make_Radiobutton_3" self.Radiobutton_3.configure(variable=self.RadioGroup_1_StringVar) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "make_Radiobutton_4" def make_Radiobutton_4(self, frame): """ Radiobutton: Color Name : at RadioGroup_1(1,4)""" self.Radiobutton_4 = Radiobutton( frame , text="Color Name", value="4", width="15") self.Radiobutton_4.grid(row=1, column=4) # >>>>>>insert any user code below this comment for section "make_Radiobutton_4" self.Radiobutton_4.configure(variable=self.RadioGroup_1_StringVar) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "RadioGroup_1_StringVar_traceName" def RadioGroup_1_StringVar_Callback(self, varName, index, mode): """ RadioGroup: Sort By: : at Main(1,1)""" pass # >>>>>>insert any user code below this comment for section "RadioGroup_1_StringVar_traceName" # replace, delete, or comment-out the following print( "RadioGroup_1_StringVar_Callback varName, index, mode",varName, index, mode ) print( " new StringVar value =",self.RadioGroup_1_StringVar.get() ) # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "dialog_validate" def validate(self): self.result = {} # return a dictionary of results self.result["RadioGroup_1"] = self.RadioGroup_1_StringVar.get() # >>>>>>insert any user code below this comment for section "dialog_validate" # set values in "self.result" dictionary for return # for example... # self.result["age"] = self.Entry_2_StringVar.get() self.result["test"] = "test message" return 1 # TkGridGUI generated code. DO NOT EDIT THE FOLLOWING. section "end" def apply(self): pass