Home > other >  MacOS/Python2.7 Tkinter Notebook Text Scrollbar abnormal response
MacOS/Python2.7 Tkinter Notebook Text Scrollbar abnormal response

Time:04-30

Under MacOS/Python 2.7 using Tkinter Notebook created 2 Tab, each Tab contained in a Text with a Scrollbar controls, my code is as follows, at run time in question:
Process is as follows:

1. The program starts, use the mouse to click on the Tab 1 for the first time, sliding Scrollbar can move
2. After the start process, use the mouse to click on the Tab for the first time 2, sliding Scrollbar can move
3. But after click Tab 2 and operating the slider, and then return to click options Tab 1, at this point the slider in the Tab 1 but there was no response, can't move! Going wrong!

Especially the following such operation error in where? What's the solution?

 # coding=utf-8 
The from Tkinter import (Tk, Text, Scrollbar)
The from Tkconstants import (END, RIGHT, X, Y, BOTH, YES)
The import TTK

Def add_tab_with_text (master, title) :
"' to TTK. Add a TAB in the Notebook, and a Text with a scrollbar is added in the TAB control ' ' '
Mytab=TTK. Frame (master)
Master. The add (mytab, text=title)

# set the Scrollbar
Scrollbar_v=Scrollbar (mytab)
Scrollbar_v. Pack (side=RIGHT, the fill=Y)

# set Text controls
Mytext=Text (mytab, width=40, height=40)
Mytext. Config (yscrollcommand=scrollbar_v. Set)
Mytext. Pack (expand=YES, the fill=BOTH)

# Text controls add content
For I in range (1, 1000) :
Line mytext. Insert (END, '% s: % d. 0 \ n' % (the title, I))

# Scrollbar action bind
Scrollbar_v. Config (command=mytext. Yview)

Main_win=Tk ()
Scrollbar main_win. Title (' test ')
Main_win. Geometry (' 800 x800 ')
Nb=TTK. Notebook (main_win)
Add_tab_with_text (nb, 'TAB 1) # create TAB 1
Add_tab_with_text (nb, 'TAB 2') # create TAB 2
Nb. Pack (fill='both', side='top')
Main_win. Mainloop ()
  • Related