0

I am trying to finish this personal project and am trying to develop a GUI for it. I only get a couple hours after work to work on it and I have been trying to fix this feature for 7 days now. I'm not one to ask for help, but it's time. It's so frustrating..

Problem: I want a tk.LabelFrame to appear in a Frame within a Canvas when I click a button. As you click the button, more Frames appear to fill the screen. I want the scrollbar to activate when there is no more room so that I can scroll.

import tkinter as tk

root = tk.Tk()
root.geometry("700x500")
mainframe = tk.Frame(root)
mainframe.pack(fill="both", expand=True)
mainframe.columnconfigure(0, weight=1)
mainframe.columnconfigure(1, weight=1)
mainframe.columnconfigure(2, weight=1)
mainframe.rowconfigure(1, weight=1)

EventsCanvas = tk.Canvas(mainframe)
EventsCanvas.grid(column=0, columnspan=2, row=1, sticky="NWES")
EventsMainframe = tk.Frame(EventsCanvas, bg="red")
EventsMainframe.pack(fill="both", expand=True)
vbar=tk.Scrollbar(EventsMainframe, orient="vertical")
vbar.pack(side="right", fill="y")
vbar.config(command=EventsCanvas.yview)
EventsCanvas.config(yscrollcommand=vbar.set)

def add():
    Event = tk.LabelFrame(EventsMainframe, text="New Event", height=100)
    Event.pack(anchor="nw", fill="x", expand=True)
EventsCanvas.configure(scrollregion=EventsCanvas.bbox("all"))

AddEvent = tk.Button(EventsMainframe, text="Add Event", command=add)
AddEvent.pack()
root.mainloop()

This is what happens when I run out of room: enter image description here

I want the scrollbar to activate and let me scroll as I keep clicking "Add Event"

vexem
  • 86
  • 3
  • Its not clear how your code is supposed to work. Please provide a [mre]. – Thingamabobs Nov 23 '21 at 21:54
  • Sorry about that. Edited the original post. – vexem Nov 23 '21 at 22:00
  • 1
    vexem: When responding to a comment, be sure to add @ followed by their username, such as @Thingamabobs, to it because doing so will cause the author to be notified. – martineau Nov 23 '21 at 22:57
  • 1
    If you want to scroll the event `LabelFrame`s you'll have to put each one in a separate canvas window created via [`Canvas.create_window()`](https://anzeljg.github.io/rin2/book2/2405/docs/tkinter/create_window.html). – martineau Nov 23 '21 at 23:49

0 Answers0