I have problem with set in Scrollbar inside Text widget in Tkinter. I know, that it's preferable to use grid to locate widgets but I want to set my widget in absolute location (x,y - red dot on GUI picture) with specified height and width.
My code:
from Tkinter import * from ttk import * class NotebookDemo(Frame): def __init__(self): Frame.__init__(self) self.pack(expand=1, fill=BOTH) self.master.title('Sample') self.master.geometry("650x550+100+50") self._initUI() def _initUI(self): self._createPanel() def _createPanel(self): # create frame inside top level frame panel = Frame(self) panel.pack(side=TOP, fill=BOTH, expand=1) # create the notebook nb = Notebook(panel) nb.pack(fill=BOTH, expand=1, padx=2, pady=3) self._FirstTab(nb) def _FirstTab(self, nb): # frame to hold content frame = Frame(nb) #textbox txtOutput = Text(frame, wrap = NONE, height = 17, width = 70) txtOutput.place(x=10, y=75) #button btnStart = Button(frame, text = 'Start', underline=0) btnStart.place(x=220, y=380) #scrollbar #vscroll = Scrollbar(frame, orient=VERTICAL, command=txtOutput.yview) #txtOutput['yscroll'] = vscroll.set #vscroll.pack(side=RIGHT, fill=Y) #txtOutput.pack(fill=BOTH, expand=Y) #add to notebook (underline = index for short-cut character) nb.add(frame, text='TAB 1', underline=0, padding=2) if __name__ == '__main__': app = NotebookDemo() app.mainloop() If I uncomment this part of code (set Scrollbar):
vscroll = Scrollbar(frame, orient=VERTICAL, command=txtOutput.yview) txtOutput['yscroll'] = vscroll.set vscroll.pack(side=RIGHT, fill=Y) My Scrollbar is located inside all window, not inside Text box:
But of course I want to have the Scrollbar inside the Text box widget (black border). If I use pack function to textbox:
txtOutput.pack(fill=BOTH, expand=Y) text widget fill in the whole window...:
I really don't know how fix this problem. Any help will be appreciated. Thank you!
EDIT:
Of course I can use place method with Scrollbar too, but I can't change length of them, because it hasn't attribute length.
vscroll.place(x=573, y=75) 



placefor the text widget, why are you not also using it for the scrollbar? Are you aware thatplacehas many options, including options to place one widget relative to another? If you are aware of them, have you tried them?placeto set the width and height of elements. For example, theheightattribute sets the height to an absolute height, therelheightattribute sets the height relative to some other widget. You should spend some time reading the documentation. While I rarely recommendplace, it's remarkably powerful when you make use of all of its features.place.