I'm working on a simple app for reading and displaying sequences of image files from within a zip file using python 3.4 with tkinter, like you might use for reading .cbz comic book files. Ideally I'd like to bind the left and right keys to show the last and next images respectively. This works fine if I specify the name of the zip file in the code; however, if I use filedialog.askopenfilename() dialogue box to specify the file, then the keyboard key bindings no longer work.
I assumed this was due to a focus issue, and I've tried setting the focus to the label to which the keys are bound (both using the label.focus_set() method and the parent option of the askopenfilename() dialogue) without success.
Code is below. Any help on this would be greatly appreciated, as it's starting to drive me nuts.
WHERE ID = o/0, i/1, etc.
答案 0 :(得分:1)
布莱恩的评论得出了答案:延迟打开文件对话直到窗口初始化后解决了问题。应用程序启动时,不是打开文件,而是创建文件打开方法,允许键绑定按预期工作。
答案 1 :(得分:0)
如果您在root.update()
之前和之后拨打askopenfilename()
,则密钥绑定会有效。