Arkadaşlar chatgpt ile sorunu çözemedim. Burada yeniyim genelde sorunumu stack üzerinden soruyorum.
Sorum şu
from tkinter import *
class ScrollFrame(Tk):
def __init__(self):
super().__init__()
self.geometry("720x360")
# Scrollable Canvas
self.canvas = Canvas(self)
self.scrollbar = Scrollbar(self, orient=VERTICAL, command=self.canvas.yview)
self.canvas.configure(yscrollcommand=self.scrollbar.set)
self.canvas.pack(side=LEFT, fill=BOTH, expand=True)
# Frame inside Canvas
self.content = Frame(self.canvas)
self.canvas.create_window((0,0), window=self.content, anchor="nw")
# Scrollbar
self.scrollbar.pack(side=RIGHT, fill=Y)
# Configure scrollbar region when the size of the frame changes
def configure_scroll_region(event):
self.canvas.configure(scrollregion=self.canvas.bbox("all"))
self.content.bind("<Configure>", configure_scroll_region)
# Bind mousewheel to scroll up/down the content
self.canvas.bind_all("<MouseWheel>", self._on_mousewheel)
# Add labels to the content
for i in range(50):
Label(self.content, text="Öğe " + str(i), background="red").pack(fill=BOTH)
# Function to scroll the canvas content up/down with mousewheel
def _on_mousewheel(self, event):
self.canvas.yview_scroll(-1*(event.delta//120), "units")
# Create the ScrollFrame object and start the main loop
scroll_frame = ScrollFrame()
scroll_frame.mainloop()
for i in range(50):
Label(self.content, text="Öğe " + str(i), background="red").pack(fill=BOTH)
fill=both genelde yazıyı genişletmesi gerek. Ancak create_window() ile bunu neden yapamıyor. Teşekkürler…