Vertical scrollbar for frame in Tkinter, Python -


my aim have scrollbar stays @ right-side of full-screen window, allowing user scroll , down through various different widgets (such labels & buttons). other answers i've seen on site, i've come conclusion scrollbar has assigned canvas in order function properly, have tried include in code have not had success with.

the below code shows simplified version of i've managed accomplish far:

from tkinter import * root = tk() root.state("zoomed") root.title("vertical scrollbar") frame = frame(root) canvas = canvas(frame) label(canvas, text = "test text 1\ntest text 2\ntest text 3\ntest text 4\ntest text 5\ntest text 6\ntest text 7\ntest text 8\ntest text 9", font = "-size 100").pack() scrollbar = scrollbar(frame) scrollbar.pack(side = right, fill = y) canvas.configure(yscrollcommand = scrollbar.set) canvas.pack() frame.pack() root.mainloop() 

i'm facing 2 issues when running code:

one scrollbar inactive, , doesn't allow user scroll down view rest of text.

the other scrollbar attached right-side of text, rather right-side of window.

so far, none of other answers i've found on site have enabled me amend code support fully-functioning scrollbar program. i'd grateful reading provide.

see again link: https://stackoverflow.com/a/3092341/7432

it shows how create scrolled frame - , can add widgets in frame.

import tkinter tk   def on_configure(event):     # update scrollregion after starting 'mainloop'     # when widgets in canvas     canvas.configure(scrollregion=canvas.bbox('all'))   root = tk.tk()  # --- create canvas scrollbar ---  canvas = tk.canvas(root) canvas.pack(side=tk.left)  scrollbar = tk.scrollbar(root, command=canvas.yview) scrollbar.pack(side=tk.left, fill='y')  canvas.configure(yscrollcommand = scrollbar.set)  # update scrollregion after starting 'mainloop' # when widgets in canvas canvas.bind('<configure>', on_configure)  # --- put frame in canvas ---  frame = tk.frame(canvas) canvas.create_window((0,0), window=frame, anchor='nw')  # --- add widgets in frame ---  l = tk.label(frame, text="hello", font="-size 50") l.pack()  l = tk.label(frame, text="world", font="-size 50") l.pack()  l = tk.label(frame, text="test text 1\ntest text 2\ntest text 3\ntest text 4\ntest text 5\ntest text 6\ntest text 7\ntest text 8\ntest text 9", font="-size 20") l.pack()  # --- start program ---  root.mainloop() 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -