LoginSignup
0
1

More than 1 year has passed since last update.

Tkinterのスクロールバー(ttk.Scrollbar)が上下しない場合の対処法

Posted at

問題

Tkinterのttk.Scrollbarでテキストボックスにスクロールバーを設置したところ、ドラッグしても上下しませんでした。

スクロールバーが機能しない様子

scroll_ng.gif

元のコード

from tkinter import *
from tkinter import ttk

root = Tk()
style = ttk.Style()

frame1 = ttk.Frame(root, padding=10)
frame1.grid()

txt = Text(frame1, height=12, width=85)
txt.grid(row=1, column=0)

scrollbar = ttk.Scrollbar(
    frame1,
    orient=VERTICAL,
    command=txt.yview)
txt["yscrollcommand"] = scrollbar.set
scrollbar.grid(row=1, column=1)

root.mainloop()

解決法

下部のscrollbar.gridにstickyオプションを付与。

scrollbar.grid(row=1, column=1, sticky=(N, S))

scroll_ok.gif

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1