Python tk scroll frame?

I am creating a simple graphical application using Tkinter with Python, but I am having problems adding a scrollbar to a single frame. The frame is visible from top to bottom on my 20 ", but in order to display everything on a netbook or any other low-resolution screen, you need a scroll bar. Here is a fragment of how I thought it would work (this happens with lists).

framelist = Tkinter.Frame(self.pmaster, relief=FLAT, borderwidth=0) framelist.pack(fill=BOTH, padx=0, pady=0) yscroll = Tkinter.Scrollbar(framelist, width=10, orient=VERTICAL) yscroll.pack(fill=Y,side=RIGHT,padx=0,pady=0) 

Although this does not work with frames. Any help on this subject from you guys would be greatly appreciated!

I am also wondering if Tkinter might be deprecated. It was the only GUI I learned at school, but that was a few years ago, and it no longer meets my requirements. Is there really a better alternative? I am on Ubuntu btw.

+4
source share
1 answer

The tkinter frame widget does not scroll. One solution is to place the entire frame in the canvas (as a canvas object) and attach a scrollbar to the canvas. You have to tell the canvas how large the scrollable area is, which you can do by getting the frame size when you place all the widgets in it. Although you might want to rethink your user interface design, scrollable frames are not very usable no matter which GUI you use.

As for whether Tkinter is out of date ... some say yes, some say no. There is a lot of tkinter misinformation, so take all the tkinter opinions with a piece of salt (even mine!). Tkinter continues to improve, it does not stagnate. If you have the luxury of using python 2.7 or higher, you have access to ttk widgets that offer special themes for the platform and additional widgets such as a laptop and hierarchical tree among others.

For alternatives you can check wxPython. In my experience, it seems to have a lot more bugs and quirks than tkinter, but they have a lot more widgets and seem to be more popular.

I like to think that the difference between tkinter and wxPython is similar to the difference between Home Depot (home improvement / lumbar store) and Ikea (prefabricated furniture that you assemble yourself) - each gives you all the pieces, do almost everything you want (tkinter) Another gives you a lot of ready-made things. Each approach has its own strengths and weaknesses.

+6
source

Source: https://habr.com/ru/post/1333629/


All Articles