下图显示了Tk窗口的右下角,该窗口由一个由画布和水平和垂直滚动条组成的框架组成。这是使用Grid方法实现的。

我无法使用Pack方法复制相同的外观。下面是我得到的结果和给出这样一个外观的示例代码。

如何使用pack方法复制网格方法的外观?
import tkinter as tk
import tkinter.ttk as ttk
root = tk.Tk()
frame = ttk.Frame( root )
frame.pack()
ysb = ttk.Scrollbar( frame, orient='vertical' )
xsb = ttk.Scrollbar( frame, orient='horizontal' )
canvas = tk.Canvas( frame, width=1000, height=700, background='green')
canvas.create_rectangle( 100, 100, 900, 600, fill='yellow' )
canvas.configure( scrollregion=canvas.bbox(tk.ALL),
xscrollcommand=xsb.set,
yscrollcommand=ysb.set )
xsb.config( command=canvas.xview )
ysb.config( command=canvas.yview )
ysb.pack( side='right', fill='y', expand=1)
xsb.pack( side='bottom', fill='x', expand=1 )
canvas.pack( side='left', fill='both', expand=1 )
#ysb.grid( row=0, column=1, sticky='ns' )
#xsb.grid( row=1, column=0, sticky='ew' )
#canvas.grid( row=0, column=0, sticky='nsew' )发布于 2020-03-05 02:27:39
您可以使用pady来实现它:
h = xsb.winfo_reqheight() # get the height of horizontal scrollbar
ysb.pack(side='right', fill='y', pady=(0,h)) # set bottom padyhttps://stackoverflow.com/questions/60531438
复制相似问题