Python Forum
[Tkinter] statusbars
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] statusbars
#1
Hi,

I need to have only 1 status bar to display some info in the bottom right and some other info in the bottom left but all in the same line (same status bar).

Here I have 2 status bars but I want to have 1 for both in the same line.

#create status bar
status_bar = Label(root, text='', bd=1, relief=GROOVE, anchor=E)
status_bar.pack(fill=X,side=BOTTOM,ipady=2)

#create status bar for file name
status_name = Label(root, text='', bd=1, relief=GROOVE, anchor=W)
status_name.pack(fill=X,side=BOTTOM,ipady=2)
Reply
#2
Why? With 2 you can set justify to make the text hug the left and right boundaries. Hide the border and it wont look like two controls If you want a border (why?) You can put both labels in a frame and give the frame a border
Reply
#3
(Jun-27-2021, 04:35 PM)deanhystad Wrote: Why? With 2 you can set justify to make the text hug the left and right boundaries. Hide the border and it wont look like two controls If you want a border (why?) You can put both labels in a frame and give the frame a border

The reason why is that I am still new to GUI and Frames. How to make it in one line? can you share an example.

Thanks
Reply
#4
I found a temp solution:

# create status bar
status_bar = Label(root, text='', bd=0,relief=GROOVE)
status_bar.pack(fill=X, side="right",padx=55,pady=20)

# create status bar for file name
status_name = Label(root, text='',bd=0, relief=GROOVE)
status_name.pack(fill=X, side="left",padx=55,pady=20)
I got what i was looking for.
Reply
#5
import tkinter as tk

count = 0

def push_me():
    """Update statusbar"""
    global count
    count += 1
    status_value['text'] = 'On' if count % 2 else 'Off'
    status_count['text'] = str(count)

root = tk.Tk()
# Make a frame that will contain the status information
status_frame = tk.Frame(root, relief=tk.SUNKEN, borderwidth=1)
status_frame.pack(side=tk.BOTTOM, expand=True, fill=tk.X, padx=5, pady=5)

# Put some stuf in the status frame
status_value = tk.Label(status_frame, text='Off', anchor='w')
status_value.pack(side=tk.LEFT, expand=True, fill=tk.X)
label = tk.Label(status_frame, text='Status Info')
label.pack(side=tk.LEFT)
status_count = tk.Label(status_frame, text='0', anchor='e')
status_count.pack(side=tk.LEFT, expand=True, fill=tk.X)

# Add a button to have the program do something 
button = tk.Button(root, text='Push Me', command=push_me)
button.pack(side=tk.TOP, padx=5, pady=5)

root.mainloop()
rwahdan likes this post
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020