###前提・実現したいこと
Pythonのtkinterを使っています。
canvasに上下方向のスクロールバーを付けて動かしたいのですが、
スクロールバーが機能していないようです。
例えば以下のコードで「test」ボタンを押せばtest0~test99まで100行表示されるはずですが、
スクロールバーが使えないので36行までしか見ることができません。
私はプログラム自体、ほとんど初心者で、なかなか上手くいかずに困っています。
どなたか原因が分かれば教えてもらえないでしょうか?
###該当のソースコード
Python
1import tkinter as tk 2 3def test(): 4 global canvasT 5 textT = '' 6 for i in range(0,100): 7 textT = textT + 'test' + str(i) + '\n' 8 canvasT.create_text(5, 5, text = textT, width = 760, anchor = tk.NW) 9 10 11def run(): 12 13 global canvasT 14 root = tk.Tk() 15 root.geometry("800x600") 16 17 frame = tk.Frame(root) 18 frame.place(x=10,y=10) 19 canvasT = tk.Canvas(frame, width =761, height = 550, bd = 1, 20 relief = tk.SUNKEN, bg = 'white') 21 sb = tk.Scrollbar(frame, orient = tk.VERTICAL, command = canvasT.yview) 22 canvasT.configure(yscrollcommand = sb.set) 23 canvasT.grid(row = 0, column = 0, sticky = tk.NW) 24 sb.grid(row = 0, column = 1, sticky = tk.NS) 25 26 button = tk.Button(frame, text = "test", command = test) 27 button.grid(row = 1, column = 0, sticky = tk.NW) 28 29 30 root.mainloop() 31 32if __name__ == '__main__': 33 run()
###補足情報(言語/FW/ツール等のバージョンなど)
Python 3.6.1を使っています。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/12/24 09:17