Reputation: 1313
In the following program, I display an Entry box that I want to be able to have a scroll bar right under my Entry box. This works but the scroll bar is at the bottom, not under the Entry box.
from tkinter import *
root = Tk()
calc = Frame(root)
calc.grid()
def saveIt():
print(text_box.get())
text_box = Entry(calc, justify=RIGHT, width=20)
text_box.grid(row=1, column = 0, pady = 5)
text_box.insert(0, "testtest1234567890testtest")
scrollbar=Scrollbar(root,orient=HORIZONTAL, command=text_box.xview, width=10)
scrollbar.grid(row=2, column = 0,sticky=E+W, pady=4)
save_button = Button(calc, text = "save")
save_button["command"] = lambda: saveIt()
save_button.grid(row=3, column = 0, pady = 5)
text_box.config(xscrollcommand=scrollbar.set)
root.mainloop()
Since I am just starting to learn Python and tkinter, any and all comments (or even solutions to the problem) will be gladly received.
Thank you in advance.
Upvotes: 0
Views: 30
Reputation: 2144
This is because the parent widget of text_box
and save_button
is calc
, whose parent is root
, and the parent of the scroll bar is also root
. So calc
as a whole is gridded above the scroll bar, and so everything inside calc
is above the scroll bar too. You just need to change
scrollbar = Scrollbar(root, orient=HORIZONTAL, command=text_box.xview, width=10)
to
scrollbar = Scrollbar(calc, orient=HORIZONTAL, command=text_box.xview, width=10)
Upvotes: 2