I create a notebook frame with two tabs, and each tab has a Text component and a Scrollbar component. but in this case the scrollbar can not work well.
the exceptions like this:
- launch this script
- select the 'tab 1', then i can drag it's scrollbar
- select the 'tab 2', then i can drag it's scrollbar
4. then, select 'tab 1' again, but I can not drag the scrollbar in 'tab 1' at this time.
os:MacOS
version:the default python V2.7.10 on mac system
is there any body know how to solve this problem? and why?
# coding=utf-8 from Tkinter import (Tk, Text, Scrollbar) from Tkconstants import (END, RIGHT, X, Y, BOTH, YES) import ttk def add_tab_with_text(master,title): '''add a tab to ttk.Notebook, and add a Text with scrollbar to each tab''' mytab = ttk.Frame(master) master.add(mytab, text=title) # set Scrollbar scrollbar_v = Scrollbar(mytab) scrollbar_v.pack(side=RIGHT, fill=Y) # set Text mytext = Text(mytab, width=40, height=40) mytext.config(yscrollcommand=scrollbar_v.set) mytext.pack(expand=YES,fill=BOTH) # Text insert message for i in range(1, 1000): mytext.insert(END, '%s line: %d.0\n' % (title,i)) # Scrollbar add bind scrollbar_v.config(command=mytext.yview) main_win = Tk() main_win.title('Scrollbar test') main_win.geometry('800x800') 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()
https://stackoverflow.com/questions/67443439/scrollbar-can-not-work-well-in-different-tabs-of-tkinter-notebook-with-python-2 May 08, 2021 at 10:04AM
没有评论:
发表评论