Python Forum
[Tkinter] Help with scroll bars
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Help with scroll bars
#1
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()
Reply
#2
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.
   
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyQt] QTableView: scroll to top cell of the screen random_nick 2 2,837 Oct-08-2022, 12:29 AM
Last Post: random_nick
Photo [PyQt] Connecting progress bars to sensors anastejzja 1 1,150 May-28-2022, 09:09 AM
Last Post: Axel_Erfurt
  [PyQt] How do I get a QScrollArea to scroll? LavaCreeperKing 9 7,812 Oct-29-2021, 08:33 AM
Last Post: Axel_Erfurt
  Treeview scroll selected node to top rfresh737 1 2,711 Apr-14-2021, 03:27 AM
Last Post: deanhystad
  [Tkinter] canvas widget scroll issue chrisdb 2 3,846 Apr-07-2021, 05:48 AM
Last Post: chrisdb
  [Tkinter] How to place scroll bar correctly scratchmyhead 1 3,943 May-18-2020, 04:17 PM
Last Post: scratchmyhead
  Scroll frame with MouseWheel Nemesis 1 3,615 Mar-25-2020, 09:29 PM
Last Post: Nemesis
  [Kivy] Why I have to click twice to scroll? Hummingbird 0 2,366 Jan-06-2020, 09:08 PM
Last Post: Hummingbird
  Require scroll bars horizontal and vertical throughout the window tejgandhi 2 2,704 Jun-28-2019, 03:13 AM
Last Post: tejgandhi
  [Tkinter] Scroll Bars going backwards goofygoo 2 2,696 Jun-07-2019, 05:07 PM
Last Post: goofygoo

Forum Jump:

User Panel Messages

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