0

in this code i try to add two frames one on the left and second on the right and i need to make the left frame fixed and add scrollbar on the right frame

from tkinter import *
from tkinter import ttk
from tkinter.ttk import *

win_width = 1200
win_hight = 720

root=Tk()
root.geometry("{}x{}".format(str(win_width),str(win_hight)))

frame_style = Style()
frame_style.configure('blue.TFrame', background='#1d96f4',highlightthickness=0)
frame_style.configure('white.TFrame', background='#FFFFFF',highlightthickness=0)
    
frame1 = ttk.Frame(root, style='blue.TFrame')
frame1.grid(row=0,column=0)
frame1.config(width=win_width*(50/100.0),height=win_hight, relief=RIDGE)
frame1.grid_propagate(0)

frame2 = ttk.Frame(root, style='white.TFrame')
frame2.grid(row=0,column=2)
frame2.config(width=win_width*(50/100.0),height=win_hight, relief=RIDGE)
frame2.grid_propagate(0)

my_canvas = Canvas(frame2, background="white",width=1100,height=720)
my_canvas.pack(side=LEFT,fill=Y)
    
my_scrollbar = ttk.Scrollbar(frame2, orient=VERTICAL , command=my_canvas.yview)
my_scrollbar.pack(side=RIGHT, fill=Y)
    
my_canvas.configure(yscrollcommand=my_scrollbar.set)
my_canvas.bind('<Configure>', lambda e: my_canvas.configure(scrollregion = my_canvas.bbox("all")))
        
second_frame = Frame(my_canvas)
my_canvas.create_window((1200,720), window=second_frame)

for i in range(0,50):
    title_label = Label(second_frame, text="Test",background='#1d96f4',foreground="#FFFFFF",font=('Helvetica', 22, 'bold'))
    title_label.place(x=20, y=40*i)

root.mainloop()

I have tried various methods but have not been able to set the look properly and I don't want to use "pack" at least inside the right frame

  • In tkinter, `Canvas` widgets are the only natively scrollable containers. – martineau Jan 26 '21 at 21:30
  • @martineau: that's not entirely true. You can use the Text widget as a container for other widgets too. – Bryan Oakley Jan 26 '21 at 21:38
  • Are you asking how to lay out the scrollbar, or how to scroll a frame full of widgets? Those are two different problems. You can't scroll the contents of a frame, but there are techniques for doing so that involve other widgets. It's not really clear what you're asking about. – Bryan Oakley Jan 26 '21 at 21:40
  • @Bryan Oakley i ask how to scroll full of widgets just for right frame without affecting the left frame – mozzmail eltayeeb Jan 26 '21 at 21:47
  • @Bryan: I was basing what I said on what's currently in the OP's question, and the right frame only contains `Label`s — but you're right that I was forgetting about scrollable `Text` widgets (now conveniently bundled with scrollbars in the [`tkinter.scrolledtext`](https://docs.python.org/3/library/tkinter.scrolledtext.html#module-tkinter.scrolledtext) module). Thanks for correcting my assertion. – martineau Jan 26 '21 at 21:49
  • Before we can answer how to scroll some widgets and not others, do you know how to solve the "scroll some widgets" part? There's already [a question](https://stackoverflow.com/questions/3085696/adding-a-scrollbar-to-a-group-of-widgets-in-tkinter) with answers for that. Perhaps you should start there. – Bryan Oakley Jan 26 '21 at 22:03
  • @bryan i understand this part clearly but the problem all explainations talk about how to add scrollbar to root frame by using canvas, i tried to assume "frame2" is the root and add scroll by using canvas but it doesn't work – mozzmail eltayeeb Jan 26 '21 at 22:17
  • Please show what you've tried. There's no canvas in your code. – Bryan Oakley Jan 26 '21 at 22:30
  • i updated the code and i added canvas part – mozzmail eltayeeb Jan 26 '21 at 22:49
  • Is there a specific reason you're using `place` to put the widgets in the inner frame? If you're doing that, there's no need for the inner frame since you can add the labels directly to the canvas. – Bryan Oakley Jan 27 '21 at 14:49
  • i think "place" give me more control in widgets, also i never mind if i use "grid" but i can't use "pack", if you add widgets to canvas directly scorllbar will not work – mozzmail eltayeeb Jan 27 '21 at 20:36

0 Answers0