1

I am trying to see different fonts and how they look in tkinter but they are going outside the window. I saw other answers on this and how to add a scrollbar but none of them are working. So is there a way I can add a scrollbar in my app or any other solution so I can view all Fonts.

Thanks

This is my code

from tkinter import Tk, font, Label
root = Tk()
x = font.families()
for i in x:
    l = Label(root, text=i, font=(i, 12))
    l.pack()
root.mainloop()

Can someone pls help

codester_09
  • 5,622
  • 2
  • 5
  • 27
  • Does this answer your question? [Adding a scrollbar to a group of widgets in Tkinter](https://stackoverflow.com/questions/3085696/adding-a-scrollbar-to-a-group-of-widgets-in-tkinter) – fhdrsdg Jan 13 '22 at 10:53

1 Answers1

0

enter image description here

from tkinter import Tk, font, Label
root = Tk()
row=0
col=0
x = font.families()
for i in x:
    l = Label(text=i, font=(i, 10))
    l.grid(column=col,row=row)
    row+=1
    if row>23:
        row=0
        col+=1
root.mainloop()

Updated

You can add scroll Bar to the window('Its a bit complicated').

from tkinter import Tk, font, Label, Frame, Canvas, Scrollbar
root = Tk()

frame = Frame(root)
frame.pack(fill='both', expand=True)


rCanvas = Canvas(frame)

rCanvas.pack(side='left', fill='both', expand=True)


scrollBar = Scrollbar(frame,command=rCanvas.yview)
scrollBar.pack(side='right', fill='y')


rCanvas.configure(yscrollcommand=scrollBar.set)

sFrame = Frame(master=rCanvas)
sFrame.bind("<Configure>", lambda e: rCanvas.configure(scrollregion=rCanvas.bbox("all")))

rCanvas.create_window((0,0), window=sFrame,anchor="nw")


x = font.families()
for i in x:
    l = Label(sFrame, text=i, font=(i, 12))
    l.pack()
root.mainloop()

enter image description here

codester_09
  • 5,622
  • 2
  • 5
  • 27