Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Tkinter program for Status Bar

Tags:

python

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

like image 688
Bharath Gupta Avatar asked Jan 18 '23 07:01

Bharath Gupta


1 Answers

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('').

like image 82
unutbu Avatar answered Jan 28 '23 03:01

unutbu