Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a bulleted list on a label widget using python tkinter

Tags:

python

tkinter

Is there any way to create a hanging indented list using the tkinter label widget? Note: Using propper standard bullets not * or -.

like image 887
Blake Rowden Avatar asked Oct 22 '25 06:10

Blake Rowden


1 Answers

I have made a class that do what you want:

class BLabel(object):
    b = "•"
    def __init__(self,master):
        import tkinter as tk
        self.l = tk.Label(master)
    def add_option(self,text):
        if self.l.cget("text") == "":
            self.l.config(text=self.b+" "+text)
        else:
            self.l.config(text=self.l.cget("text") +"\n"+ self.b + " "+text)

You can use it like:

lbal = BLabel(master=master)    
lbal.add_option("Bullet1")    #<-- adding item
lbal.add_option("Bullet2")    #<-- adding item
lbal.l.pack()     #<-- Packing

Here is an example code:

import tkinter as tk

root = tk.Tk()

class BLabel(object):
    b = "•"
    def __init__(self,master):
        import tkinter as tk
        self.l = tk.Label(master)
    def add_option(self,text):
        if self.l.cget("text") == "":
            self.l.config(text=self.b+" "+text)
        else:
            self.l.config(text=self.l.cget("text") +"\n"+ self.b + " "+text)



lbal = BLabel(master=root)
lbal.add_option("Bullet1")
lbal.add_option("Bullet2")
lbal.l.pack()        

Here is the output of above code:

bullet in tkinter label

In that way, you can use pack , place or grid. Example:

Grid:

lbal.l.grid(row=0,column=0)

Place:

lbal.l.place(x=0,y=0)

Pack:

lbal.l.pack()
like image 71
Black Thunder Avatar answered Oct 24 '25 20:10

Black Thunder



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!