def createButtons(self, frame, vals, text): # create canvas for select all and deselect all buttons canv = Canvas(frame, width=220, height=10) canv.create_line(20, 10, 220, 10, dash=(2, 4)) canv.pack(fill=X) # create each button separately selectAll = Button(frame, text="Select All", command=lambda: self.allButtons(vals, "Select")) selectAll.pack() selectTrialToolTip = ToolTip(selectAll, delay=toolTipDelay, text="Select all " + text + " for analysis.") deselectAll = Button( frame, text="De-Select All", command=lambda: self.allButtons(vals, "De-Select")) deselectAll.pack() deselectTrialToolTip = ToolTip(deselectAll, delay=toolTipDelay, text="Deselect all " + text + " marked for analysis.") return (selectAll, deselectAll)
def addPot(self): potOneVariable = StringVar(self.master) potOneVariable.set(self.potsList[0]) potOneOption = OptionMenu(self.potFrame, potOneVariable, *self.potsList) potOneOption.grid(row=self.potLastRow, column=0) potVariable = DoubleVar() potVariable.trace("w", lambda name, index, mode, potVariable=potVariable: self.potAmountChanged(potVariable)) potOneAmount = Entry(self.potFrame, textvariable=potVariable) #Pad on the right to have space between the pots/envelopes column. potOneAmount.grid(row=self.potLastRow, column=1, padx=(0, 6)) #Create tooltip for Entry potEntryTooltip = ToolTip(potOneAmount, "Enter amount to add/remove") self.potLastRow = self.potLastRow + 1 potWidgets = DoubleValueWidgets(potOneOption, potOneVariable, potOneAmount, potVariable, potEntryTooltip) self.potsWidgets.append(potWidgets) potOneVariable.trace( "w", lambda name, index, mode, potOneVariable=potOneVariable: self. potSelectionChanged(potWidgets)) self.potSelectionChanged(potWidgets) self.setRemovePotButtonState() self.potAmountChanged(None) return potWidgets
def createToolTip(self, widget, text): toolTip = ToolTip(widget) def enter(event): toolTip.showtip(text) def leave(event): toolTip.hidetip() widget.bind('<Enter>', enter) widget.bind('<Leave>', leave) return toolTip
def create_tool_tip(widget, text): toolTip = ToolTip(widget) def enter(event): toolTip.show_tip(text) def leave(event): toolTip.hide_tip() widget.bind('<Enter>', enter) widget.bind('<Leave>', leave)
def addEnvelope(self): envelopeOneVariable = StringVar(self.master) envelopeOneVariable.set(self.envelopeList[0]) envelopeOneOption = OptionMenu(self.envelopeFrame, envelopeOneVariable, *self.envelopeList) #Pad on the left to have space between the pots/envelopes column. envelopeOneOption.grid(row=self.envelopeLastRow, column=0, padx=(6, 0)) envelopeVariable = DoubleVar() envelopeVariable.trace( "w", lambda name, index, mode, envelopeVariable=envelopeVariable: self. envelopeAmountChanged(envelopeVariable)) envelopeOneAmount = Entry(self.envelopeFrame, textvariable=envelopeVariable) envelopeOneAmount.grid(row=self.envelopeLastRow, column=1) #Create tooltip for Entry envelopeEntryTooltip = ToolTip(envelopeOneAmount, "Enter amount to add/remove") self.envelopeLastRow = self.envelopeLastRow + 1 envelopeWidgets = DoubleValueWidgets(envelopeOneOption, envelopeOneVariable, envelopeOneAmount, envelopeVariable, envelopeEntryTooltip) self.envelopesWidgets.append(envelopeWidgets) envelopeOneVariable.trace( "w", lambda name, index, mode, envelopeOneVariable=envelopeOneVariable: self.envelopeSelectionChanged(envelopeWidgets)) self.envelopeSelectionChanged(envelopeWidgets) self.setRemoveEnvelopeButtonState() self.envelopeAmountChanged(None) return envelopeWidgets
Entry2Var = StringVar() Entry2Var.trace('w', lambda name, index, mode, Entry2Var=Entry2Var: Entry2callback(Entry2Var)) def Entry2callback(Entry2Var): CheckForMatchInKeyList() # ------------------------------ # Build the gui and start the program # This entry box displays the time and date Entry1 = Entry(Main) Entry1.pack(side=TOP, fill=X, expand=TRUE) ToolTip(Entry1, 'Time and date display') # Enter the search values def ShowCalender(): global CalendarWindow if CalendarWindow: try: CalendarWindow.destroy() except: CalendarWindow = None CalendarWindow = tkinter.Tk() CalendarWindow.title('Tk Calendar') ttkcal = CAL.Calendar(CalendarWindow, firstweekday=calendar.SUNDAY) ttkcal.pack(expand=1, fill='both')
def Entry2Enter(Junk): Entry2.delete(0, tk.END) Entry2.insert(0, DM.EditorResults) CheckForMatchInKeyList() Entry2.focus_force() ToolTip(Entry2, 'Search box (Entry2)')
# ------------------------------ Entry2Var = tk.StringVar() Entry2Var.trace('w', lambda name, index, mode, Entry2Var=Entry2Var: Entry2callback(Entry2Var)) def Entry2callback(Entry2Var): CheckForMatchInKeyList() # ------------------------------ # Build the gui and start the program # This entry box displays the time and date Entry1 = tk.Entry(Main) Entry1.pack(side=tk.TOP, fill=tk.X, expand=tk.TRUE) ToolTip(Entry1, 'Time and date display (Entry1)') # Enter the search values def ShowCalender(): global CalendarWindow if CalendarWindow: try: CalendarWindow.destroy() except Exception as e: print('Unable to read project file\n' + str(e)) CalendarWindow = None CalendarWindow = tkinter.Tk() CalendarWindow.title('Tk Calendar') ttkcal = CAL.Calendar(CalendarWindow, firstweekday=calendar.SUNDAY)
def createComponents(self): # Create text fonts for components self.titleFont = tkFont.Font(family="Arial", size=18) self.componentFont = tkFont.Font(family="Helvetica", size=16) # Create a frame for the title section # ====================================================================== titleFrame = Frame(self) titleFrame.pack(fill=X) # Create the title label title_label = Label(titleFrame, text="Data Processor For Pigeon Experiment", font=self.titleFont) title_label.pack(fill=X, expand=True) title_labelTooltip = ToolTip( title_label, delay=toolTipDelay + 500, text="This program was created by Chris Cadonic for use \ in the laboratory of Dr. Debbie Kelly.") # Create a canvas for drawing a separation line canv = Canvas(titleFrame, width=840, height=10) canv.create_line(0, 10, 840, 10) canv.pack(fill=X, anchor=CENTER, expand=True) # Create a frame for the bottom section # ====================================================================== footerFrame = Frame(self) footerFrame.pack(anchor=S, expand=True, side=BOTTOM) # Create a run button runButton = Button(footerFrame, width=200, text="Run Processing", command=self.run) runButton.pack(fill=Y) runToolTip = ToolTip( runButton, delay=toolTipDelay, text="Run analysis based on the groups and animals\ selected above.") # Create and populate group and trial button frames # ====================================================================== trialFrame = Frame(self) trialFrame.pack(expand=True, anchor=W, side=LEFT) # Create a checkbox for each test group self.trialLabels = [ "Non-reinforced training", "Control 1", "Control 2", "Feature Only", "Geometry Only", "Affine" ] self.trialKeys = ["Nrtr", "C1", "C2", "FO", "GO", "AF"] self.trialTooltips = [ "Non-reinforced training group.", "Control group 1", "Control group 2", "Group where an extra wall and a \ feature wall are placed in the environment to create an enclosed square.", "Group where the feature wall is removed, but the geometry of the environment \ remains the same.", "Group where the feature wall is moved to the end of the \ long wall." ] self.trialVals = [] # create all of the group buttons for num in range(len(self.trialLabels)): self.trialVals.append(IntVar()) trialButtons.append( Checkbutton(trialFrame, text=self.trialLabels[num], variable=self.trialVals[num], font=self.componentFont)) trialButtons[-1].pack(pady=8) trialButtonTooltips.append( ToolTip(trialButtons[-1], delay=toolTipDelay, text=self.trialTooltips[num])) # create select/deselect all buttons self.createButtons(trialFrame, self.trialVals, "experimental phases") # Create a frame for handling all of the birds # ====================================================================== animalsFrame = Frame(self, width=100, height=360) animalsFrame.pack(expand=True, anchor=CENTER, side=RIGHT) self.animalCanvas = Canvas(animalsFrame, width=100, height=360, scrollregion=(0, 0, 500, 1000)) self.newFrame = Frame(self.animalCanvas, width=100, height=360) self.animalScrollbar = Scrollbar(animalsFrame, orient="vertical", command=self.animalCanvas.yview) self.animalCanvas.configure(yscrollcommand=self.animalScrollbar.set) self.animalScrollbar.pack(side="right", fill="y") self.animalCanvas.pack(side="top") self.animalCanvas.create_window((0, 0), window=self.newFrame, anchor='nw') self.newFrame.bind("<Configure>", self.scrollFunc) self.animals = list(allData.keys()) self.animalVals = [] # Create a button for each bird in the data directory for bird in range(len(self.animals)): self.animalVals.append(IntVar()) animalButtons.append( Checkbutton(self.newFrame, text=self.animals[bird], variable=self.animalVals[bird], font=self.componentFont)) self.animalVals[-1].set(1) animalButtons[-1].pack(pady=6) # create select/deselect all buttons self.createButtons(animalsFrame, self.animalVals, "animals") # Create a frame for handling all of the additional buttons # ====================================================================== buttonsFrame = Frame(self) buttonsFrame.pack(fill=X, expand=True) # Threshold label thresholdLabel = Label(buttonsFrame, text="Change threshold: ") # Threshold entry box thresholdBox = Entry(buttonsFrame, width=10) thresholdBox.pack() thresholdBox.insert(0, defaultThreshold) thresholdBoxTooltip = ToolTip( thresholdBox, delay=toolTipDelay, text="Change this value to set a new threshold value \ for calculating the max distance away from a goal to be kept for data analysis." ) # Re-analyze with new thresholdBox reformatButton = Button( buttonsFrame, text="Apply new threshold", command=lambda: self.checkReformat(thresholdBox, False)) reformatButton.pack() reformatTooltip = ToolTip( reformatButton, delay=toolTipDelay, text="Click to apply any changes to threshold box above.") # Reset threshold to defaultThreshold resetButton = Button( buttonsFrame, text="Reset threshold and run", command=lambda: self.checkReformat(thresholdBox, True)) resetButton.pack() resetButtonTooltip = ToolTip( resetButton, delay=toolTipDelay, text="Click to reset threshold to default value.") # Create a sort button self.sortOutput = IntVar() sortButton = Checkbutton(buttonsFrame, text="Sort", variable=self.sortOutput, font=self.componentFont) sortButton.pack() sortTooltip = ToolTip( sortButton, delay=toolTipDelay, text="Select to auto-sort the output excel spreadsheets by \ trial type.") # Create a quit button quitButton = Button(buttonsFrame, text="Quit", command=self.quit) quitButton.pack() quitToolTip = ToolTip(quitButton, delay=toolTipDelay, text="Quit the program and close the GUI.")