Согласно @jasonharper, мне будет очень трудно использовать
msg.window_create( tk.INSERT, window=pbar )
, чтобы расположить индикатор в нужном месте
Ниже сценарий показывает ответ на мои вопросы 1, 2 и 3. Вкратце, методы .place()
и .place_forget()
могут использоваться для позиционирования .Progressbar()
так, как я желаю. Кроме того, .winfo_reqwidth()
и .winfo_width()
могут использоваться для определения соответствующего размера существующего виджета.
Пересмотренный тестовый сценарий:
import tkinter as tk
import tkinter.ttk as ttk
root = tk.Tk()
msg = tk.Text( root, width=60, height=5 )
pbar = ttk.Progressbar( msg, mode='indeterminate',
orient=tk.HORIZONTAL,
)
msg.grid( row=0, column=0, padx=10, pady=10 )
# .winfo_reqwidth() gives the width of .Text(). Subtract 2 pixel to account for
# its left and right borderwidth. The resultant is should be the width of the
# .Progressbar().
pbar['length'] = msg.winfo_reqwidth()-2
# Use .place() method to give the illusion of placing progressbar inside .Text()
# Method 1:
#pbar.place( x=1, y=msg.winfo_reqheight()-pbar.winfo_reqheight(),
# bordermode="outside" )
# Method 2:
pbar.place( anchor='sw', x=1, y=msg.winfo_reqheight(), bordermode="outside" )
# Use .place_forget() and .place() to hide and reappear .Progressbar().
root.after( 3000, lambda: pbar.place_forget() )
root.after( 6000, lambda: pbar.place( anchor='sw', x=1,
y=msg.winfo_reqheight(),
bordermode="outside" ) )