Python Forum
[Tkinter] Scrollbar in tkinter
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Scrollbar in tkinter
#1
I don't know why this scrollbar not working. Please help Sad

canvas = Canvas(frame, bd=0,
                xscrollcommand=xscrollbar.set,
                yscrollcommand=yscrollbar.set)

canvas.grid(row=0, column=0, sticky=N+S+E+W)

xscrollbar.config(command=canvas.xview)
yscrollbar.config(command=canvas.yview)

frame.pack()
entry1 = Entry(canvas,bg='blue',fg = 'white',width=70)

entry2 = Entry(canvas,bg='red',fg = 'white',width=70)
entry1.pack()
entry2.pack()


def pressed(ro):
    global button1
    y=e.get()
    if type(y)==str and y!="":
        entry1 = Entry(canvas,bg='blue',width=70)
        entry2 = Entry(canvas,bg='red',width=70)
        entry1.pack()
        entry2.pack()
        
         
e=Entry(root,width=124)
e.pack()

button1 = Button(root,text= "Submit",command =lambda: pressed(0))
button1.pack()
Reply
#2
Please provide enough of script to run.
scrollbar should go something like, but cannot test as your code is not runnable without modification.
canvas = Canvas(frame,bd=0)
canvas.grid(row=0, column=0, sticky=N+S+E+W)
cheight = canvas.winfo_height()

yscrollbar = tk.Scrollbar(canvas, orient=tk.VERTICAL, command=canvas.yview)
yscrollbar.grid(row=0, rowspan=self.treeheight, column=1, sticky='ns')
xscrollbar = tk.Scrollbar(canvas, orient=tk.HORIZONTAL, command=canvas.xview)
xscrollbar.grid(row=self.cheight + 1, column=0, sticky='ew')
canvas.congigure(yscroll=yscrollbar)
canvas.congigure(xscroll=xscrollbar)

frame.pack()
entry1 = Entry(canvas,bg='blue',fg = 'white',width=70)
 
entry2 = Entry(canvas,bg='red',fg = 'white',width=70)
entry1.pack()
entry2.pack()
 
 
def pressed(ro):
    global button1
    y=e.get()
    if type(y)==str and y!="":
        entry1 = Entry(canvas,bg='blue',width=70)
        entry2 = Entry(canvas,bg='red',width=70)
        entry1.pack()
        entry2.pack()
         
          
e=Entry(root,width=124)
e.pack()
 
button1 = Button(root,text= "Submit",command =lambda: pressed(0))
button1.pack()
Reply
#3
A really nice, concise description of the problem that I grabbed from Bryan Oakley over on stackoverflow
Quote:You can only associate scrollbars with a few widgets, and the root widget and Frame aren't part of that group of widgets.

The most common solution is to create a canvas widget and associate the scrollbars with that widget. Then, into that canvas embed the frame that contains your label widgets. Determine the width/height of the frame and feed that into the canvas scrollregion option so that the scrollregion exactly matches the size of the frame.

Why put the widgets in a frame rather than directly in the canvas? A scrollbar attached to a canvas can only scroll items created with one of the create_ methods. You cannot scroll items added to a canvas with pack, place, or grid. By using a frame, you can use those methods inside the frame, and then call create_window once for the frame.

The rest is here
https://stackoverflow.com/questions/3085...41#3092341

What is boils down to is you create a canvas because that is one of the few things you can scroll. Next you create all your controls in a frame. Finally you place the frame in the canvas using anvas.create_window.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Help create scrollbar in chatbot with tkinter on python fenec10 4 1,432 Aug-07-2023, 02:59 PM
Last Post: deanhystad
  [Tkinter] Scrollbar apffal 7 3,061 Oct-11-2021, 08:26 PM
Last Post: deanhystad
Question [Tkinter] How to configure scrollbar dimension? water 6 3,374 Jan-03-2021, 06:16 PM
Last Post: deanhystad
  [PyQt] scrollbar in tab issac_n 1 3,543 Aug-04-2020, 01:33 PM
Last Post: deanhystad
  [Tkinter] Help with Scrollbar JJota 6 3,586 Mar-10-2020, 05:25 AM
Last Post: Larz60+
  [Tkinter] Scrollbar doesn't work on Canvas in Tkinter DeanAseraf1 3 9,304 Sep-19-2019, 03:26 PM
Last Post: joe_momma
  [Tkinter] Same Scrollbar for two text area smabubakkar 3 2,810 Jun-19-2019, 05:26 PM
Last Post: Denni
  Scrollbar rturus 5 15,004 Jun-06-2019, 01:04 PM
Last Post: heiner55
  [PyGUI] Create a scrollbar in GUI to add test cases mamta_parida 1 3,584 Sep-27-2018, 11:57 AM
Last Post: Larz60+
  [Tkinter] Scrollbar problem & general organization weatherman 13 13,324 Apr-16-2017, 12:55 PM
Last Post: weatherman

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020