Python ttk notebook showing selected tab wrongly
<pre><code>from tkinter import *
from tkinter import ttk

class MainGame(Frame):
    def __init__(self, parent):
        Frame.__init__(self, parent)   
        self.parent = parent        
        self.initUI()

    def tab_change(self, event):
        tab_id = self.page.index('current')
        print(tab_id, self.page.tab(tab_id, 'text'))

    def initUI(self):
        global canvas
        self.parent.title('PythonPage')
        self.pack(fill = BOTH, expand = 1)
        self.page = ttk.Notebook(self, width = 646 ,height = 629)
        self.page1 = Frame(self)
        self.page2 = Frame(self)
        self.page.add(self.page1, text = 'Tab1')
        self.page.add(self.page2, text = 'Tab2')
        self.page.bind('&lt;ButtonPress-1&gt;', self.tab_change)
        self.page.pack(expand = 0, anchor = 'w', side = 'top')

root = Tk()
root.geometry('925x650')
main = MainGame(root)
root.mainloop()
</code></pre>

<p><code>tab_change</code> can show their id and names, but not correctly.</p>

<p>When <code>Tab1</code> is clicked, I clicked <code>Tab2</code> but it still print <code>0 Tab1</code>, it needs one more click to print <code>1 Tab2</code> .</p>

<p><code>Tab2</code> click to <code>Tab1</code> is the same, it needs one more click to show the current selected tab.</p>

<p>I want to find why the tabs need double click? And how can I get selected tab correctly by a single click?</p>

<p>Change:</p>

<pre><code>self.page.bind('&lt;ButtonPress-1&gt;', self.tab_change)
</code></pre>

<p>To:</p>

<pre><code>self.page.bind('&lt;ButtonRelease-1&gt;', self.tab_change)
</code></pre>

<p>Because unless you have released the pressed button, the tab hasn't changed!</p>

<p><a href="http://i.stack.imgur.com/xLNxC.gif" rel="nofollow"><img src="http://i.stack.imgur.com/xLNxC.gif" alt="enter image description here"></a></p>

python tkinter tabs ttk