from Tkinter import *
class StatusBar(Frame):
def __init__(self, master):
Frame.__init__(self, master)
self.label = Label(self, bd=1, relief=SUNKEN, anchor=W)
self.label.pack(fill=X)
def set(self, format, *args):
self.label.config(text=format % args)
self.label.update_idletasks()
def clear(self):
self.label.config(text="")
self.label.update_idletasks()
root = Tk()
root.update()
d =StatusBar(root)
d.pack()
mainloop()
Hi Friend.This is my code for Status bar.Even though i didn't get any error or warning. I had failed to obtain the status bar. But my Widget is getting opened with empty in it.Can any one please help me in this aspect.
Thank you
It's there; it's just very small because none of the widgets requested much space.
If you put some text in the Label, or gave root
a geometry, it would be easier to see:
import Tkinter as tk
class StatusBar(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master)
self.variable=tk.StringVar()
self.label=tk.Label(self, bd=1, relief=tk.SUNKEN, anchor=tk.W,
textvariable=self.variable,
font=('arial',16,'normal'))
self.variable.set('Status Bar')
self.label.pack(fill=tk.X)
self.pack()
root=tk.Tk()
d=StatusBar(root)
root.geometry('300x100')
root.mainloop()
By the way, to allow the text inside the label to change, use a tk.StringVar
.
Calling self.variable.set(...)
will change the label's text. And to clear it just call self.variable.set('')
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With