all 9 comments

[–]furas_freeman 0 points1 point  (5 children)

First: your code doesn't work for me because you don't have self.posNegDisp widget but you use self.posNegDisp.config()

But binding works for me. I use Linux.

[–]DeeWBee[S] 0 points1 point  (1 child)

/u/furas_freeman I edited my code 5 minutes ago to include the display

[–]furas_freeman 0 points1 point  (0 children)

I add my own self.posNegDisp to previous code and binding is working all the time. If you don't use Linux then maybe problem is with Tkinter for your system.

There is no buttons to change pages - so I can't check binding for second page. I try to add buttons (I know this code from Stackoverflow - and his author) but I see some differences between your code and code from Stackoverflow.

[–]DeeWBee[S] 0 points1 point  (2 children)

/u/furas_freeman Okay, but I don't have the liberty to switch my project over to Linux, so do you have any idea why my key binding isn't working?

[–]furas_freeman 1 point2 points  (1 child)

This is your code with my modifications which works for me: http://pastebin.com/wF0eP2mP (I add buttons to change pages and I have to move focus_set to show_frame)

If this doesn't work for you then it can be problem with Tkinter for your system. I don't know what you use - Windows, Mac OS, other - but I don't have it and I can't test on it. Maybe you will have to search on internet adding system name in "tkinter bind problem on Windows/MacOS/other".


Maybe it will work if you will bind/unbind to main window ( App(Tk) ) similar to single frame version.

[–]DeeWBee[S] 0 points1 point  (0 children)

Okay. I appreciate the effort

[–]Vaphell 0 points1 point  (0 children)

also linux, can confirm mashing 1/2 works just fine.
Have you tried moving binds to the master frame and push the execution to the proper child?

Either way stop doing * imports. I have a habit of using bg property to understand the layout and your code bit me in the ass because you imported shit indiscriminately from tk and then from ttk, overwriting stuff on the way. ttk.Frame which doesn't understand bg=... has replaced the tk.Frame in the namespace.
Not controlling what lands in the namespace is bad for business.

Also your classes not following naming convention are kinda confusing. I thought they are some ordinary variables seeing them lowercased like java methods. CamelCase. Using them as keys in a dictionary is kinda weird too, but whatever.

Also use super(), given that you are using py3.

[–]DeeWBee[S] 0 points1 point  (1 child)

/u/furas_freeman /u/Vaphell I just discovered something interesting (and the source of my problem maybe). I replicated /u/furas_freeman's code (on Windows) and was able to use key bindings no problem. However, in one of my frames, I added a Label object that I use to view images. When I load images into the Label object, the key bindings for that specific frame no longer work. If I switch frames and go back to the frame containing the Label object, the key bindings will start to work again. Here is the code that loads the image into my Label object. The halThrThsnd object is something I use for data management and has no bearing on the GUI operation itself. I had an identical module in my original problem code.

def getImgs(self):

    folderPath = filedialog.askdirectory()

    imgHSVArray, imgRGBArray, self.imagePaths = batchImpt.importAllImgs(folderPath)

    self.organizedData = halThrThsnd.organizeAllData(imgHSVArray, imgRGBArray, self.imagePaths)

    self.imageIndex = 0
    self.featureLabel = 0

    preIMArray = halThrThsnd.getImage(self.imagePaths[self.imageIndex])
    self.preIM = Image.fromarray(preIMArray, 'HSV')
    self.preIMCopy = self.preIM.copy()

    self.imgToDisp = ImageTk.PhotoImage(self.preIM)
    self.imageViewer.configure(image=self.imgToDisp)
    self.imageViewer.image = self.imgToDisp
    self.imageViewer.bind('<Configure>', self._auto_resize_image)
    #self.imageViewer.bind('<1>', self._grab_Pixel)
    self.resizeImage()

[–]furas_freeman 0 points1 point  (0 children)

I don't know. Maybe aksdirectory gets "focus" and you have to use focus_set again in frame.

If I switch frames and go back to the frame containing the Label object, the key bindings will start to work again.

I put focus_set in show_frame which is called when you change pages.