Python Forum

Full Version: Help with scroll bars
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have written this code, but the scrollbar shoows in a small window, I am trying to make the scroll bar window bigger or even better if I could make it fullscreen. Can someone please help me, why is the scrollbar showing up in a small window?, and how can i adjust the size?

Thanks for alle the help
Regards:
Kraco

import tkinter as tk
from tkinter import ttk
import random

root = tk.Tk()
container = ttk.Frame(root)
canvas = tk.Canvas(container)
scrollbar = ttk.Scrollbar(container, orient="vertical", command=canvas.yview)
scrollable_frame = ttk.Frame(canvas)

def DiceResults():
    Dice_list = [2, 3, 4, 5, 6, 7, 9, 10, 11, 12]
    random_num = random.choice(Dice_list)
    if (random_num == 2):
        tk.Label(scrollable_frame, text="this is number two").pack()
    elif (random_num == 3):
        tk.Label(scrollable_frame, text="this is number three").pack()
    elif (random_num == 4):
        tk.Label(scrollable_frame, text="this is number three").pack()
    else:
        tk.Label(scrollable_frame, text="this is number twelve " + str(random_num)).pack()

scrollable_frame.bind("<Configure>", lambda e: canvas.configure (scrollregion=canvas.bbox("all")))

canvas.create_window((0,0), window=scrollable_frame, anchor="nw")

canvas.configure(yscrollcommand=scrollbar.set)

for i in range(1):
    ttk.Label(scrollable_frame, text="Sample scrolling label").pack()
    Button1 = tk.Button(scrollable_frame, text='Roll Dices', width=25, command=DiceResults)
    Button1.pack(pady=10)
    Button2 = tk.Button(scrollable_frame, text='Quit', width=25, command=root.destroy)
    Button2.pack(pady=10)

container.pack()
canvas.pack(side="left", fill="y", expand=True)
scrollbar.pack(side="right", fill="y")

#root.attributes("-fullscreen",True)
root.mainloop()
I just tried your cod on Linux, and it seems fine. (click image below)
The window is not full, so nothing will scroll until full.
[attachment=997]