How to attach a Scrollbar to a Text widget?

前端 未结 3 763
北荒
北荒 2020-11-28 07:54

I am trying to attach a scrollbar to my Text field and have been unable to do so. Here is the segment of code:

self.scroller = Scrollbar(self.root)
self.scro         


        
3条回答
  •  天命终不由人
    2020-11-28 08:34

    You can use tkinter frame for it, this is very simple way =>

    import tkinter as tk
    from tkinter import *
    root = tk.Tk()
    
    f = tk.Frame(root)
    f.place(x=10, y=20)
    
    scrollbar = Scrollbar(f)
    t = tk.Text(f, height=10, width=10, yscrollcommand=scrollbar.set)
    scrollbar.config(command=t.yview)
    scrollbar.pack(side=RIGHT, fill=Y)
    t.pack(side="left")
    
    root.mainloop()
    

提交回复
热议问题