Apr-09-2017, 09:54 AM
Below is the relevant portion of code that I would like some assistance with. Eventually I throw a ton of scale widgets on the Frame, but I am unable to scroll with the mousewheel. Also, prior to writing this code I never used the Canvas, just frames, but I needed a scroll bar and hijacked code I found online to get the scrollbar working. Now I want to scroll with the mouse and I tried to put more hijacked code in.
(1) Are a Canvas and a Frame both necessary to get a scrollbar added to a pile of widgets?
(2) If so, the GUI works, but is my code "pythonic"
(3) Why can't I scroll with the mouse
Thanks for any help!
(1) Are a Canvas and a Frame both necessary to get a scrollbar added to a pile of widgets?
(2) If so, the GUI works, but is my code "pythonic"
(3) Why can't I scroll with the mouse
Thanks for any help!
### Initialize the Tkinter GUI for user interaction ### self._customGUI = Tk(baseName="userGUIs") arrowX = self._customGUI.winfo_pointerx() self._customGUI.protocol('WM_DELETE_WINDOW', self._abnormAbort) self._customGUI.title("Blend Models") ### Center the user GUI on the screen ### totWidth = self._customGUI.winfo_screenwidth() middlePoint = totWidth/2 if arrowX >= middlePoint: useWidth = middlePoint else: useWidth = 0 self._guiXPos = useWidth ### Size of initial user GUI self._setupGUIheight=425 self._setupGUIwidth=325 self._customGUI.geometry("%dx%d+%d+%d" % (self._setupGUIwidth, self._setupGUIheight, self._guiXPos, 0)) ### Create a canvas within the main GUI defined early for widget organization ### self._buttonCanvas = Canvas(self._customGUI, borderwidth=0) ### Create a frame to put in the Canvas self._buttonFrame = Frame(self._buttonCanvas) ### Create a vertical scrollbar self._vertScroll = Scrollbar(self._customGUI, orient="vertical",width=18,command=self._buttonCanvas.yview) self._buttonCanvas.configure(yscrollcommand=self._vertScroll.set) self._vertScroll.pack(side="right",fill="y") self._buttonCanvas.pack(side="left",fill="both",expand=True) self._buttonCanvas.create_window((0,0), window=self._buttonFrame, anchor="nw") self._buttonFrame.bind("<Configure>", lambda event, canvas=self._buttonCanvas: self._buttonCanvas.configure(scrollregion=self._buttonCanvas.bbox("all"))) self._buttonFrame.bind("<Button-4>", lambda event, canvas=self._buttonCanvas: self._buttonCanvas.yview('scroll', -1, 'units')) self._buttonFrame.bind("<Button-5>", lambda event, canvas=self._buttonCanvas: self._buttonCanvas.yview('scroll', 1, 'units'))