Reputation: 95
I want to create a ScrolledText widget using scrolledtext module for creating a GUI in python . I have successfully created a ScrolledText widget , however i am not able to add a horizontal scroll bar to it .
e3=ScrolledText(window3,width=24,height=13)
e3.grid(row=5,column=1,rowspan=6,columnspan=4)
The above code snippet is used to create the ScrolledText widget .
ScrolledText Widget Screenshot
The widget contains only vertical scrollbar . I want to add a horizontal scrollbar to it as well . Any idea how to do it ?
UPDATE: The ScrolledText widget is being used to accept a multiline input . Check the picture attached.
Upvotes: 3
Views: 5630
Reputation: 385870
You can implement a scrolled text widget yourself with a text widget and a couple of scrollbars.
Here's an example that puts a text widget and two scrollbars in a frame, so that they appear as if they are a single widget. This is pretty much exactly what the ScrolledText
widget does:
import tkinter as tk
root = tk.Tk()
textContainer = tk.Frame(root, borderwidth=1, relief="sunken")
text = tk.Text(textContainer, width=24, height=13, wrap="none", borderwidth=0)
textVsb = tk.Scrollbar(textContainer, orient="vertical", command=text.yview)
textHsb = tk.Scrollbar(textContainer, orient="horizontal", command=text.xview)
text.configure(yscrollcommand=textVsb.set, xscrollcommand=textHsb.set)
text.grid(row=0, column=0, sticky="nsew")
textVsb.grid(row=0, column=1, sticky="ns")
textHsb.grid(row=1, column=0, sticky="ew")
textContainer.grid_rowconfigure(0, weight=1)
textContainer.grid_columnconfigure(0, weight=1)
textContainer.pack(side="top", fill="both", expand=True)
root.mainloop()
Upvotes: 5