简体   繁体   中英

how can i scroll text on a python tk/tinker Label?

I'm trying to add a simple log output to a tk window/frame.

So far i only found how to (easily) add a vertical scrollbar on canvas , entry lists and text (which is a fullblown text editor and has no textvariable linking support)

The Label can't be attached to a scrollbar (easily) because it lacks the yview attribute.

#my naive attempt:...
self.lbl_log = tk.Label(self, width=80, height=10, textvariable=self.string_log)
self.lbl_log.pack(side="top")
self.vsb = tk.Scrollbar(self, orient="vertical", command=self.lbl_log.yview)
self.lbl_log.configure(yscrollcommand=self.vsb.set)

AttributeError: 'Label' object has no attribute 'yview'

is there any easy and convenient way to scroll a label widget with several lines in python tk? I don't necessarily have to use a Label i just like it because it is simple and has the textvariable convenience) so i'm open to alternative widgets for this problem.

No, there isn't an easy way to scroll a label. If you need to scroll multiple lines, a label is the wrong choice of widget. If you need to scroll multiple lines of text, the text widget is the proper widget.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM