python - Tkinter: widgets not highlighting on <Tab> event -


i'm running python 2.7.9 on mac. i've been unable figure out why when run programs entry widgets highlight each time hit tab key move next widget. following test code. when run script , hit tab key, first entry field highlighted. next time hit tab key, second entry field highlighted. however, when hit tab key move button widget, button receiving focus there not highlight visually indicate user focus.

the optionmenu widget skipped altogether, mystery. both radiobutton , checkbox receives focus, button widget, , again no highlight present.

i've tried variety of .config() arrangements no avail. missing?

from tkinter import *  class app:      def __init__(self, master):         frame = frame(master)         frame.grid()          #tests make sure button receives focus.         def yup(self):             print "yup"          entry1 = entry(frame)         entry1.pack()          entry2 = entry(frame)         entry2.pack()          button1 = button(frame, text="test")         button1.pack()         button1.bind('<return>', yup)          var1 = intvar()         c = checkbutton(frame, text="expand", variable=var1)         c.pack()          var2 = stringvar()         radio = radiobutton(frame, text="test", variable=var2, value=1)         radio.pack()          var3 = stringvar()         optionmenu1 = optionmenu(frame, var3, "one", "two", "three")         optionmenu1.pack()   root = tk() root.geometry('400x400+0+0') app = app(root)  root.mainloop() 

it sounds need configure os x "full keyboard access" allow tab focus on ui controls (versus text boxes , lists).

in yosemite (10.10), setting can found under system preferences > keyboard > shortcuts, , can toggled control+f7. note has nothing python, , occur system-wide.

edit

so after doing more testing, there appears issues actual highlighting of widgets using tk on mac. below condensed version of original sample minor modifications simplicity.

import tkinter tk import ttk # more on in minute  class app(tk.frame):      def __init__(self, master):          tk.frame.__init__(self, master)          self.master = master          entry1 = tk.entry(self)         entry1.pack()          entry2 = tk.entry(self)         entry2.pack()          button1 = tk.button(self, text="test", command=self.yup)         button1.pack()      def yup(self):         print("yup")      # ...  root = tk.tk() app = app(root).pack()  root.mainloop() 

with full keyboard access enabled mentioned, can verify button indeed receive focus: on third tab, after first 2 entry widgets, hitting <space> "clicks" button , prints stdout. there no visual indication button selected.

changing button tk.button ttk.button "fixes" this, , indeed show normal "selection" frame around button when tabbing through ui.

button1 = tk.button(self, text="test", command=self.yup)  # change to: button1 = ttk.button(self, text="test", command=self.yup) 

i have no idea why is, , don't know consensus tkinter.ttk is, prefer ttk "plain" tk seems produce widgets appear more "native" os x in experience. note removed bind statement, , reporting result using os x default of space activate ui elements full keyboard access enabled.

more on ttk here. note not tk widgets have ttk implementation, , there ttk widgets not exist in tk.

lastly below find "ttk" version of original snippet.

import tkinter tk import ttk  class app(ttk.frame):      def __init__(self, master):          ttk.frame.__init__(self, master)          self.master = master          entry1 = ttk.entry(self)         entry1.pack()          entry2 = ttk.entry(self)         entry2.pack()          button1 = ttk.button(self, text="test", command=self.yup)         button1.pack()      def yup(self):         print("yup")      # ...  root = tk.tk() app = app(root).pack()  root.mainloop() 

hope helps.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -